1

I have the following dataframe.

sample <- climate <- tibble(
Month = c("1/1/2019","2/1/2019","3/1/2019","4/1/2019","5/1/2019","6/1/2019","7/1/2019","8/1/2019","9/1/2019","10/1/2019","11/1/2019","12/1/2019","1/1/2020","2/1/2020","3/1/2020"),
Count = c(38,   33, 31, 27, 30, 34, 33, 39, 33, 23, 24, 21, 23, 23,30),
Reactions = c(5211,3324,21295,15331,2973,1078,7413,8077,1066,5486,6087,1600,3625,2578,2069),
Ratio = c(1371,1866,6445,4914,925,363,218,245,335,1530,352,525,1506,1112,873)
)

I want to create a ggplot with the primary axis being the count and on the secondary axis i want the reactions and the ratio. This is what i'm using, but the primary axis does not scale.

ggplot() + 
geom_bar(mapping = aes(x = sample$Month, y = sample$Count), stat = 'identity', group = 1) +
geom_line(mapping = aes(x = sample$Month , y=sample$Reactions), size = 3, color = "red", group = 1) + 
geom_line(mapping = aes(x = sample$Month , y=sample$Ratio, color = "blue"), size = 3, group = 1) +
scale_y_continuous(name = "Posts", sec.axis = sec_axis(trans = ~., name = "Count"))

Any help will be appreciated

0 Answers0