Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't change ylab in ggplot

When I create this plot, I realize even I specify ylab, it is not applied to the output plot, whereas other labs works perfectly.
Code below:

 saturation = function(po2,L){((po2/5.5)*(1+(po2/5.5))^3+
                                L*(po2/300)*(1+(po2/300))^3)/((1+(po2/5.5))^4+L*(1+(po2/300))^4)} #enter the equation
library(ggplot2)
library(ggtext)

labels = '<p><span style="color: #304d63;">L = 10</span>, 
<span style="color: #b2e7e8;">L = 30</span>, 
<span style="color: #8fb9aa;">L = 100</span>, 
<span style="color: #f2d096;">L = 300</span>, 
<span style="color: #ed8975;">L = 1000</span>, 
<span style="color: #8c695d;">L = 3000</span></p>'
color_scheme = c("#304D63", "#B2E7E8", "#8FB9aa",'#F2D096',"#Ed8975",'#8C695D')
Ls = c(10,30,100,300,1000,3000)

plot = ggplot()+ xlim(0,150)
for(i in 1:6){
  plot = plot + geom_function(fun = saturation,args = list (L= Ls[i]),color = color_scheme[i])

}
plot = plot + labs(title = 'figure 1', xlab = 'pO2',ylab = '%hemeglobin bound',subtitle=(labels))+
  theme(plot.subtitle = element_markdown())

plot

and the output is below:1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Inside the labs function, the argument to label the y axis is called y, not ylab

plot + 
  labs(title = 'figure 1', x = 'pO2', y = '%hemeglobin bound', 
       subtitle = labels) +
  theme(plot.subtitle = element_markdown())

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading