3

I have quarterly data as follows (key represents year-quarter):

       tic    saleq    key
1     AAPL 1346.202 1990-2
2     AAPL 1364.760 1990-3
3     NOK  1354.090 1990-4

Because it now is in a single column, I'm able to plot the line with the combined column as the x-axis:

p <- ggplot(example, aes(x = key, y = saleq))
p + geom_line(aes(color=tic, group=tic)) + ylab("Quarterly sales")

However, this (logically) generates a lot of duplicate 'year' values (ie. x column is littered 2014-1, 2014-2)

I'd like to be able to plot this with ggplot2 by 'grouping' by year & then showing the quarter just above it on the x-axis. Similar to plotting a line graph in Excel as with this data. Is something like this possible in ggplot2?

example excel graph

I've been forwarded to this question, which tries something similar. However, this does not take into account naming multiple 'groups' of x-values: would I have to dynamically calculate where the middle of each year is (to take into account the # of quarters of data per year?)

Community
  • 1
  • 1
MattV
  • 1,353
  • 18
  • 42
  • Perhaps http://stackoverflow.com/questions/26294883/adding-more-x-axix-labels-in-ggplot/26295796#26295796 will help. – shadow Jan 12 '15 at 14:53

0 Answers0