是否有可能使用 ggplot2 在繪圖中添加第三個 y 軸?我想在圖中顯示三個不同的資料源。我已經添加了第二個 y 軸,對于下一個資料集,比例再次非常不同,為什么我現在正在尋找解決方案。
到目前為止,我只找到了如何添加第二個軸,例如 [here] 所示。(
使用的資料
df <- iris
df$Sepal.Length <- df$Sepal.Length * 100
df$Petal.Width <- df$Petal.Width * 1000
uj5u.com熱心網友回復:
這是一個非常笨拙的解決方案,它基于從先前繪制的圖形中提取元素并編輯網格物件。它可能會給你一個可行的解決方案,也可能不會。
source("https://raw.githubusercontent.com/davidearn/plague_growth/master/analysis/plots/3axes.R")
set.seed(101)
dd <- data.frame(x=rnorm(20),y=rnorm(20))
library(ggplot2)
gg0 <- ggplot(dd)
g1A <- gg0 geom_point(aes(x,y))
g1B <- gg0 geom_point(aes(x,10*y))
g1C <- gg0 geom_point(aes(x,100*y))
## use return_gtable = TRUE if planning to add further axes
g2 <- combine_axes(g1A,g1B,add_pos="l", return_gtable=TRUE)
g3 <- combine_axes(g2,g1C,add_pos="l")
print(g3)

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/450209.html
