Home > Software engineering >  How to remove text that appeared in the chart?
How to remove text that appeared in the chart?

Time:10-16

Am trying to plot 2 different columns of a time series data type in a single plot, however the year appears which seems to block the view of the chart. How do I remove the year in the chart so that I can see the charts nicely?

enter image description here The below code is how i created the chart

data('fertil3')
fertil = ts(fertil3, frequency = 1, start = 1913)
plot(x = fertil[,"year"], y = fertil[,"gfr"], type="l", col="red", ylim = c(0, 250), xlab="Time", ylab="")
par(new=TRUE)
plot(x = fertil[,"year"], y = fertil[,"pe_1"], type="l", col="blue", ylim = c(0, 250),xlab="Time", ylab="")

CodePudding user response:

You should convert the time series object ts to as.numeric which then is a vector and can be used to plot it like lines like this:

library(wooldridge)
data('fertil3')
fertil = ts(fertil3, frequency = 1, start = 1913)
plot(x = as.numeric(fertil[,"year"]), y = as.numeric(fertil[,"gfr"]), type="l", col="red", ylim = c(0, 250), xlab="Time", ylab="")
par(new=TRUE)
plot(x = as.numeric(fertil[,"year"]), y = as.numeric(fertil[,"pe_1"]), type="l", col="blue", ylim = c(0, 250),xlab="Time", ylab="")

Created on 2022-10-15 with reprex v2.0.2

CodePudding user response:

Perhaps plot as a base R time series...

Saves a bit of typing too!

library(wooldridge)


data('fertil3')
fertil = ts(fertil3, frequency = 1, start = 1913)
plot.ts(fertil[, c("gfr", "pe_1")],  plot.type = "single", col=c("red", "blue"), ylim = c(0, 250), xlab="Time", ylab="" )

Created on 2022-10-15 with reprex v2.0.2

  • Related