我只想将y- axis1 DATA(左轴,Var1,虚线)绘制为 log10 比例。因此,虚线在 y 轴上看起来更高,并且 1 和 2 之间的差异会很明显。
我尝试了几件事,但不起作用(我相信我以错误的顺序/位置使用它们),例如:
+coord_trans(y='log10')
--> 空图
scale_y_continuous(trans = log10_trans()
,... --> 使 Var1 和 Var 2 均为 log10
scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),labels = trans_format("log10", math_format(10^.x)))
--> 使 y 轴 log10 并删除 y-axis2 (Var2)
data<- data.frame(
Day=c(1,2,3,1,2,3,1,2,3),
Name=rep(c(rep("a",3),rep("b",3),rep("c",3))),
Var1=c(1090,484,64010,1090,484,64010,1090,484,64010),
Var2= c(4,16,39,2,22,39,41,10,3))
ggplot(data) +
geom_bar(aes(fill=Name, y=Var2*1000, x=Day),stat="identity", colour="black", position= position_stack(reverse = TRUE))+
geom_line(aes(x=Day, y=Var1),stat="identity",color="black", linetype="dotted", size=0.8)+
geom_point(aes(Day, Var1), shape=8)+
labs(title= "",
x="",y=expression('Var1'))+
scale_y_continuous(
sec.axis=sec_axis(~./1000, name= expression(paste("Var2"))))+
theme_classic()+
scale_fill_grey(start = 1, end=0.1,name = "", labels = c("a", "b", "c"))