0
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)

I have the data given as above. I would like to plot months on x-axis, Apartment_no on left y-axis and Days on right y-axis. I would like the readings to just appear as Dots on the graph. I have tried the following 3 codes but none of them seems to be working out for me.

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(Heat_clean,aes(month,Apartment_no))+geom_point() p+scale_y_continuous(sec.axis = sec_axis(Days))

I also tried something with facet_wrap which can be seen in the following code, but it gave a weird graph which is not understandable.

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

Furthermore, since I have a large data similar to this, can I highlight the dots in my plot where ever the Days is below 10.

  • Does this answer your question? [ggplot with 2 y axes on each side and different scales](https://stackoverflow.com/questions/3099219/ggplot-with-2-y-axes-on-each-side-and-different-scales) – Ben G Nov 18 '19 at 13:47
  • Yea, I actually looked at it & tried to customize the code according to my problem but unfortunately it hasn't worked out in my case. – Kartik Kaushal Nov 18 '19 at 13:55
  • So, see the response by Hadley who is the author of `ggplot`. Basically, you can't plot a second axis unless it's a conversion. – Ben G Nov 18 '19 at 14:13
  • Your two y-axes are of different scales (and one is a factor at that). I don't think its possible. – K.J.J.K Nov 18 '19 at 18:00

0 Answers0