I have data of two time series that I would like to plot together. The x-axis will be date and the y-axis will be a line graph of series 1, while the point sizes will be scaled based on the numeric value of series 2. However, when series 2 = 0, I would like ggplot to not display a point at all. I've tried setting the range of point sizes from a minimum of 0, but it still displays points for values of 0.
Here's code to reproduce the problem:
Dates = c("2015-05-01", "2015-05-02", "2015-05-03", "2015-05-04", "2015-05-05", "2015-05-06")
Dates = as.Date(Dates)
Series1 = c(0,2,8,5,3,1)
Series2 = c(0,0,5,0,10,5)
df = data.frame(Dates, Series1, Series2)
ggplot(data = df)+
geom_line(aes(x=Dates, y = Series1))+
geom_point(aes(x=Dates, y = Series1, size = Series2))+
scale_size_continuous(range = c(0, 5))
This produces the following graph:
How can I make ggplot2 not create a point when Series2 = 0, but still display the line? I also tried replacing 0's with NA's for Series2, but this results in the plot failing.
scale_size_area
takes just a max size in order to put 0 values at a size 0 – camille