이전 게시물 how-to-use-facets-with-a-dual-y-axis-ggplot에서 설명한대로 두 번째 축 기능을 사용하여 두 개의 다른 데이터를 사용하는 문제가 발생했습니다.ggplot2에서 이중 y 축 (두 번째 축) 사용
geom_point
및 geom_bar
을 사용하려고하지만 geom_bar 데이터 범위가 다르므로 그래프에 표시되지 않습니다.
다음은 내가 시도한 것입니다.
point_data=data.frame(gr=seq(1,10),point_y=rnorm(10,0.25,0.1))
bar_data=data.frame(gr=seq(1,10),bar_y=rnorm(10,5,1))
library(ggplot2)
sec_axis_plot <- ggplot(point_data, aes(y=point_y, x=gr,col="red")) + #Enc vs Wafer
geom_point(size=5.5,alpha=1,stat='identity')+
geom_bar(data=bar_data,aes(x = gr, y = bar_y, fill = gr),stat = "identity") +
scale_y_continuous(sec.axis = sec_axis(trans=~ .*15,
name = 'bar_y',breaks=seq(0,10,0.5)),breaks=seq(0.10,0.5,0.05),limits = c(0.1,0.5),expand=c(0,0))+
facet_wrap(~gr, strip.position = 'bottom',nrow=1)+
theme_bw()
bar_data가 제거 된 것을 알 수있다. 이 맥락에서 함께 그려 줄 수 있습니까 ??
들으
이 모든 작업을 수행하려면'geom_bar'에서 막대 값을 15로 나눠야하고'limits'를 .1에서 시작하는 대신 0으로 내려야합니다 (막대가 0에서 시작됨). – aosmith