0

I have the line chart below and I would like to plot a bar chart of the "V" column in the "bigDF" data frame on a secondary y axis. Is this possible? I have to use ggplot in this instance. Can this be done?

Here is the code which you can run:

library('ggplot2')
time <- as.POSIXct(c("2014-12-10 20:51:53.103","2014-12-10 20:56:54.204",
                     "2014-12-10 20:57:54.204"), tz= "GMT")
p <- c(49.32, 60,50)
s <- c("B","","S")
pointcolor <- c("green","","red")
V <- c(100,500,600)
share <- c(35,0,6)
pointsize <- c(10,10,10)
shapeType <- c(16,10,16)
bigDF <- data.frame(time=time, p=p, s=s, pointcolor=pointcolor, share=share,
                    pointsize=pointsize, shapeType=shapeType,V = V)
bigDF
ggplot(bigDF, aes(x=time, y=p)) + geom_line() + 
  geom_point( aes(shape = as.factor(shapeType), 
                  size = pointsize, color = pointcolor))+ 
  ylab("this is primary y axis")+  
  xlab("this is the x axis")
scale_color_manual(values = levels(as.factor(bigDF$pointcolor)))
scale_size_manual(values = levels(as.factor(bigDF$pointsize)))

That code produces:

enter image description here

but I would like to show a bar chart of the "V" column in the "bigDF" dataframe on a secondary axis and I would like to label that secondary axis. Can you help?

Thank you.

Prradep
  • 5,506
  • 5
  • 43
  • 84
user3022875
  • 8,598
  • 26
  • 103
  • 167
  • It's not possible by design, as explained [here](http://stackoverflow.com/a/3101876/3204472). If you absolutely need to do it, other answers to that question give first steps to some workarounds, but they aren't pretty. – Joe Feb 09 '15 at 21:49
  • Joe - Can it be easily done without using ggplot? – user3022875 Feb 09 '15 at 22:07
  • @Henrik, the question is definitely a duplicate but the question/answer that you link to indicates that it is not possible. – user20650 Feb 09 '15 at 22:07
  • http://stackoverflow.com/questions/28282996/add-second-y-scale-for-two-series-and-reduce-dates-on-x-axis-ggplot has a link to a question showing how to add a second y-axis and another saying why it may not always be a good idea. – user20650 Feb 09 '15 at 22:09

0 Answers0