我正在尝试使用ggplot2
包绘制一条线和一个条形图,但使用函数时似乎很难获得两个不同的 y 轴facet_grid()
......
我想在我当前的绘图中添加一个条形图,其中包含数据框中每个产品的频率(可变频率)。任何帮助都会非常棒!!
temp = data.frame(Product=as.factor(c("L","P","41","43")),
Freq = c(0.2,0.8,0.7,0.3),
rate = c(14,17,12,20),
var= c("QUAL","QUAL","OCCU","OCCU"))
temp %>% ggplot() + theme_grey(base_size=20) +
geom_line(aes(x=Product, y=rate, group=var))+
geom_point(aes(x=Product, y=rate, group=var))+
geom_label( aes(x=Product,y=rate,label=paste0(rate,"%") )) +
facet_grid(.~ var, scales = "free") +
theme(legend.position="none", axis.text.x=element_text(angle=45, vjust=0.1)) -> p2