0

I have a very simple question:

My data is as follows:

dateq equal.weighted 2000q1 100 2000q2 103 2000q3 105 2000q4 108

I used the following code to plot this data, but the graph shows no line inside, could you please help me, many thanks!

ggplot(GlobalPriceData, aes(dateq, equally.weighted)) + geom_line() +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
Vera Lee
  • 29
  • 4
  • 2
    Possible duplicate of [Line plot with factor variables in R](https://stackoverflow.com/questions/25011518/line-plot-with-factor-variables-in-r) – pogibas Feb 01 '19 at 09:36
  • Use `group = 1` within `aes` as suggested in the linked duplicate post, also your column is called `equal.weighted` not `equally.weighted` – pogibas Feb 01 '19 at 09:36

1 Answers1

0

You should trasform your date column in an appropriate date format:

library(zoo) # for as.yearqtr() and scale_x_yearqtr()
d$dateq <- as.yearqtr(d$dateq)

ggplot(d, aes(x = dateq, y = equal.weighted)) +
  geom_line() +
  scale_x_yearqtr(limits = c(min(d$dateq), max(d$dateq)),
                  format = "%YQ%q") # this sets the proper scale format for the ax

enter image description here

Data:

tt <- "dateq     equal.weighted
2000q1     100
2000q2     103
2000q3     105
2000q4     108"

d <- read.table(text=tt, header = T)
RLave
  • 8,144
  • 3
  • 21
  • 37