0

I have a dataframe like this

Data2 <- structure(list(year = c(2008L, 2009L, 2010L, 2011L, 2012L, 2013L, 
2014L, 2015L, 2016L, 2017L, 2018L, 2019L, 2008L, 2009L, 2010L, 
2011L, 2012L, 2013L, 2014L, 2015L, 2016L, 2017L, 2018L, 2019L, 
2008L, 2009L, 2010L, 2011L, 2012L, 2013L, 2014L, 2015L, 2016L, 
2017L, 2018L, 2019L), variable = c("Yahoo", "Yahoo", "Yahoo", 
"Yahoo", "Yahoo", "Yahoo", "Yahoo", "Yahoo", "Yahoo", "Yahoo", 
"Yahoo", "Yahoo", "Amazon", "Amazon", "Amazon", "Amazon", "Amazon", 
"Amazon", "Amazon", "Amazon", "Amazon", "Amazon", "Amazon", "Amazon", 
"Google", "Google", "Google", "Google", "Google", "Google", "Google", 
"Google", "Google", "Google", "Google", "Google"), value = c(1L, 
0L, 0L, 0L, 1L, 1L, 3L, 4L, 3L, 10L, 9L, 0L, 0L, 1L, 0L, 0L, 
3L, 2L, 2L, 3L, 8L, 9L, 12L, 3L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 
0L, 1L, 2L, 4L, 0L)), class = "data.frame", row.names = c(NA, 
-36L))

and I would like to plot it using this:

library(ggplot2)
ggplot(Data2, aes(year, variable, size = value, color = variable)) +
    geom_point()

enter image description here

However the problem with this plot is that the x-axis has not for example 2007 but it has 2007.5 and the bubbles in not in the symmetric place

How can I fix it?

OTStats
  • 1,820
  • 1
  • 13
  • 22
Elr Mant
  • 507
  • 1
  • 4
  • 14

1 Answers1

1

you could manually set the breaks to be whole years:

ggplot(Data2, aes(year, variable, size = value, color = variable)) +
  geom_point() + 
  scale_x_continuous(breaks = seq(min(Data2$year),max(Data2$year),by=1))

enter image description here

OTStats
  • 1,820
  • 1
  • 13
  • 22
Wil
  • 3,076
  • 2
  • 12
  • 31