ggplot 이중축 dual axis
Second Axis 추가
https://shanmdphd.rbind.io/post/2018-09-06-dualy/
### DATA ----------------------------------------------------------------------- data <- iris %>% as.data.table() ### EDA ------------------------------------------------------------------------ data[ , .(Sepal.Length, Petal.Width)] %>% summary() ### PLOT ----------------------------------------------------------------------- p1 <- data %>% ggplot(aes(x=1:nrow(data))) + geom_line( aes(y=Sepal.Length, color='SL')) + geom_line( aes(y=Petal.Width, color='PW')) p1 <- p1 + labs(x="" , y="Sepal.Length(SL) or Petal.Width(PW)" ) p1 p2 <- data %>% ggplot(aes(x=1:nrow(data))) + geom_line( aes(y=Sepal.Length, color='SL')) + geom_line( aes(y=Petal.Width*4, color='PW')) p2 <- p2 + labs(x="", y="Sepal.Length(SL)") # Adata Second Axis p2 <- p2 + scale_y_continuous(sec.axis=sec_axis(~./4, name="Petal.Width(PW)")) p2