反转主 y 轴并反转辅助轴

时间:2021-04-23 17:03:52

标签: r ggplot2

我有以下两张图:

#Rainfall
ggplot(d, aes(x = Date, y = Rainfall, rm.na=TRUE)) +
  geom_col(size = 1, fill = "darkblue") + theme(axis.text.x=element_text(angle=60, hjust=1, size=7)) + ylab("Rainfall (in)") + scale_x_date(date_labels = "%B") +
 ggsave(paste0("~/Desktop/plots", ".png"), width = 30, height = 20, units = "cm") 

#A1 DTW
ggplot(d1, rm.na=TRUE) +
geom_line(aes(x = Date, y = DTW, color = WellID)) + scale_x_date(date_labels = "%B") + theme(axis.text.x=element_text(angle=60, hjust=1, size=7)) + ggtitle("Depth to Water Area 1") + scale_y_continuous(trans="reverse", name="DTW (ft BGS)", limits=c(20, 0)) + ggsave(paste0("~/Desktop/plots", ".png"), width = 30, height = 20, units = "cm") 

#Rainfall #A1 DTW 我试图将它们与反转的主轴 (DTW) 结合起来,但辅助轴 (Rainfall) 恢复到正常方向。我正在使用以下代码,但它不会使主反转或具有正确的限制。

#A1 DTW + Rainfall
ggplot() +
geom_line(d1, rm.na=TRUE, mapping = aes(x = Date, y = DTW, color = WellID)) + scale_x_date(date_labels = "%B") + theme(axis.text.x=element_text(angle=60, hjust=1, size=7)) + ggtitle("Depth to Water Area 1") + scale_y_continuous(trans="reverse", name="DTW (ft BGS)", limits=c(20, 0)) +
  geom_col(d, mapping = aes(x = Date, y = Rainfall, rm.na=TRUE), size = 1, fill = "darkblue") + theme(axis.text.x=element_text(angle=60, hjust=1, size=7)) + scale_y_continuous(sec.axis = sec_axis(~.*1, name = "Rainfall (in)")) + ggsave(paste0("~/Desktop/plots", ".png"), width = 30, height = 20, units = "cm") 

#A1 DTW + Rainfall 有什么帮助吗?

0 个答案:

没有答案
相关问题