Italics not working on labels in ggplot2?

不打扰是莪最后的温柔 提交于 2019-12-08 04:13:30

问题


Please consider the following plot. I have maintained details of structure, packages, etc, as I am not sure what is causing the issue. I am sure this is quite simple, but I am unable to make it work.

require(reshape2)
require(ggplot2)
require(dplyr)
require(tidyr)

    #setting up labels -- find out why italics expression isn't working??
Fig.labels<-c(expression(paste(italic("C. ret"), "-0d")),
expression(paste(italic("C. ret"), "-4d")),
expression(paste(italic("C. ret"), "-14d")),
expression(paste(italic("M. pan"), "-4d")),
expression(paste(italic("M. pan"), "-14d")))


A1_0d_ret<-rnorm(1:100,20)
A2_4d_ret<-rnorm(1:100,18)
A3_14d_ret<-rnorm(1:100,30)
A4_4d_pan<-rnorm(1:100,7)
A5_14d_pan<-rnorm(1:100,40)

data<-data.frame(A1_0d_ret,
A2_4d_ret,
A3_14d_ret,
A4_4d_pan,
A5_14d_pan)

long.data<-melt(data)

long.data_<-separate(data = long.data, col = variable, into = c("group", "treatment", "species"), sep = "_", remove=FALSE)

ggplot(long.data_, aes(x=treatment, y=log(value), group=variable))+
geom_boxplot(outlier.shape = NA, width=0.2 )+
scale_x_discrete("Never mind weird plot", labels=Fig.labels)+
theme_classic()

I wish to mix normal fonts with italics. Why aren't italics working on the labels from expression()? I have seen so many similar working examples.

Edit: this is on RStudio 1.1.456


回答1:


Since your code seems fine by some users, as seen in this created plot by your code (mention that the first tick is normal font for visualization purpose) you can try update your packages

updating single packages

for the librarys like ggplot2 you can use the update.packages() function (documentation)

updating r

for this answer it's more easy to link an old stackoverflow question

You have to download R from the website and install it again manually, sadly there is no option to do this in RStudio. For more help and a more detailed walktrough check out the old post.



来源:https://stackoverflow.com/questions/51935883/italics-not-working-on-labels-in-ggplot2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!