'ggplot 2 of y-axis : the change is only in the level of y2 scale not the whole plot

Upon setting second axis trans=~.*0.5 but the change is only in the level of text (y2 scale), not the whole plot. hopefully, by that setting, the plot will transform to a new plot and not only "the text of scale".

library(ggplot2)
  ggplot(j, aes(x=hour1))+ theme_classic()+
  geom_point(aes(y = HR),shape=3, size=1,stroke=1, col = "black") + 
  geom_point(aes(y = TC),shape=2, size=1,stroke=1, col = "black") +
  xlab("Hour")+ggtitle("RH and T for monthly mean st_ID 96195")+
  scale_y_continuous(
    # Features of the first axis
    name = "RH (%)",
    # Add a second axis and specify its features
    sec.axis = sec_axis( trans=~.*0.5, name="T (C)")
  )

output

wanted output



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source