ggplot中的辅助轴

时间:2020-04-02 11:57:54

标签: r ggplot2

我有以下数据框。

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)
)

我想创建一个ggplot,主轴为计数,在次级轴上,我想要反应和比率。这是我正在使用的,但是主轴无法缩放。

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"))

任何帮助将不胜感激

0 个答案:

没有答案
相关问题