用双Y轴绘制ggplot

时间:2019-11-18 13:29:41

标签: r

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
Apartment_no <- c("1-SV","1-SV","1-SV","1-SH","1-SH","1-SH","1-1V","1-1V","1-1V","1-1H","1-1H","1-1H","3-SV","3-SV","3-SV","3-1V","3-1V","3-1V","3-1H","3-1H","3-1H")
month <- c("September","October","November","September","October","November","September","October","November","September","October","November","September","October","November","September","October","November","September","October","November")
Days <- c("2","19","28","2","19","28","2","19","28","2","19","28","25","31","28","12","13","24","8","26","19")
Heat_data <- data.frame(Apartment_no,month,Days)

我有上面给出的数据。我想在x轴上绘制月份,在y轴上绘制Apartment_no,在y轴上绘制天数。我希望读数在图表上仅显示为点。我尝试了以下3个代码,但似乎没有一个适合我。

Heat_data%>%ggplot()+geom_point(aes(x=month,y=Apartment_no),col="red")+geom_point(x=month,y=Days,col="blue")+scale_y_continuous(name = expression("Apartment_no"),sec.axis = sec_axis(name = "Days"))

Heat_data%>%ggplot()+geom_point(mapping = aes(x=month,y=Apartment_no,size=3,shape=21,fill="blue"))+scale_y_continuous(name = expression("Apartment_no"),sec.axis = sec_axis(name = Days))

p <-ggplot(卫生清洁,aes(月,公寓编号))+ geom_point() p + scale_y_continuous(sec.axis = sec_axis(Days))

我还使用facet_wrap进行了一些尝试,可以在以下代码中看到它,但是它给出了一个不可理解的怪异图形。

Heat_data%>%ggplot(aes(month,value,fill=Apartment_no))+geom_col()+coord_flip()+facet_wrap(~Apartment_no)

此外,由于我有与此类似的大数据,因此我可以突出显示天数低于10的情节中的点。

0 个答案:

没有答案
相关问题