斜体在ggplot2中的标签上不起作用? [英] Italics not working on labels in ggplot2?

查看:157
本文介绍了斜体在ggplot2中的标签上不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下情节.我已经维护了结构,程序包等的详细信息,因为我不确定是什么引起了该问题.我确信这很简单,但是我无法使其正常工作.

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

我希望将普通字体与斜体混合使用.为何斜体不对expression()的标签起作用?我看到了很多类似的工作示例.

这是在RStudio 1.1.456上

解决方案

由于某些用户对您的代码似乎还满意,如您在代码中创建的图表中所见(提到第一个刻度是用于可视化目的的常规字体),您可以尝试更新您的软件包

更新单个软件包

对于类似ggplot2的库,您可以使用update.packages()函数(文档)

更新r

对于此答案,链接旧的 stackoverflow问题

更容易

您必须从网站下载 R并手动重新安装,可惜没有在RStudio中执行此操作的选项.要获得更多帮助和更详细的步道,请查看旧帖子.

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

解决方案

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.

这篇关于斜体在ggplot2中的标签上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆