1

I need help with the modification of a plot with y-axis. In Excel I don't have trouble, but the hard part is in R. Besides, I uploaded an example of the final plot in excel. It is not relevant the data you used.

I will appreciate your help.

Required double y-axis with polynomial function plot:

enter image description here

#Make lm model
Model<- lm(V~ T,data=data1)
summary(Model)
anova(Model)
HSD.test(Model, 'T', group = T, MSerror, alpha = 0.05, console = T)

#Make eq

eq <- function(data1){
  m<- lm(V~T); 
  eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(r)^2~"="~r2, 
                   list(a = format(unname(coef(m)[1]), digits = 2),
                        b = format(unname(coef(m)[2]), digits = 2),
                        r2 = format(summary(m)$r.squared, digits = 3)))
}

#Make plot
ggplot(data, aes(x=Time, y=mean))+ 
  geom_line()+
  geom_smooth(method=loess)+
  stat_regline_equation(label.y = 4.0e-06, aes(label=..eq.label..))+
  stat_regline_equation(label.y = 3.8e-06, aes(label=..rr.label..))+
  geom_pointrange(aes(ymin=mean-se, ymax=mean+se))+
  theme(
    line = element_line(colour = "black", size = 1, linetype = 1, lineend = "butt"), 
    rect = element_rect(fill = "white", colour = "black", size = 1, linetype = 1), 
    aspect.ratio = 1,
    plot.background = element_rect(fill = "white"),
    plot.margin = margin(1, 1, 1, 1, "cm"),
    
    axis.text = element_text(size = rel(2.5), colour = "#000000", margin = 1), 
    strip.text = element_text(size = rel(0.8)), 
    axis.line = element_blank(), 
    axis.text.x = element_text(vjust = 0.2, angle=0), 
    axis.text.y = element_text(hjust = 1), 
    axis.ticks = element_line(colour = "#000000", size = 1.2), 
    axis.title.x = element_text(size = 30, vjust=0.5), 
    axis.title.y = element_text(size = 30, angle = 90), 
    axis.ticks.length = unit(0.1, "cm"), 
    
    
    legend.background = element_rect(colour = NA), 
    legend.margin = unit(0.15, "cm"), 
    legend.key = element_rect(fill = "grey95", colour = "white"), 
    legend.key.size = unit(1.2, "lines"), 
    legend.key.height = NULL, 
    legend.key.width = NULL, 
    legend.text = element_text(size = rel(2.0)), 
    legend.text.align = NULL, 
    legend.title = element_text(size = rel(2.0), face = "bold", hjust = 0), 
    legend.title.align = NULL, 
    legend.position = "right", 
    legend.direction = NULL, 
    legend.justification = "right", 
    legend.box = NULL, 
    
    
    panel.background = element_rect(fill = "#ffffff", colour = "#000000",
                                    size = 2, linetype = "solid"), 
    
    panel.border = element_rect(colour = "black", fill=NA, size=2), 
    
  )+
  ylab(expression(Volume~(m^3))) + xlab(expression(Time~(min)))
Phil
  • 7,287
  • 3
  • 36
  • 66
  • This may be helpful for you: https://stackoverflow.com/questions/3099219/ggplot-with-2-y-axes-on-each-side-and-different-scales – Grasshopper_NZ Dec 28 '22 at 07:29

0 Answers0