在ggplot轴标签中删除斜体周围的间距

问题描述 投票:1回答:1

我正在制作下面的情节。但是,当我用标签中的n斜体时,它会在它之后增加间距。如何控制斜体周围的间距?这是代码的最小版本:

ggplot(data.frame()) + 
    labs(labs(x=expression("Proportion of "~italic(n)-"gram Model (1-"*gamma*")")))

这是实际情节:

enter image description here

完整代码(数据太大而无法发布):

ggplot(all_pplx, aes(x=(1-Weight), y=perplexity_val)) +
  geom_line(aes(color=`n-gram`)) +
  scale_y_log10() +
  # scale_x_reverse() +
  labs(title="",
       x=expression("Proportion of "~italic("n")-"gram Model ("*gamma*")"),
       y="Perplexity") +
  theme(axis.text.x = element_text(size=12),
        axis.text.y = element_text(hjust = 1, size=12),
        axis.title.x = element_text(size=12,face="bold"),
        axis.title.y = element_text(size=12),
        plot.title = element_text(hjust = 0.5, size=12),
        legend.position = c(0.15, 0.7), 
        legend.background = element_rect(color = "black", 
                                         fill = "grey90", 
                                         size = .2, 
                                         linetype = "solid")) +
  ggsave('emnlp_new-exp1.pdf', device='pdf')
r ggplot2
1个回答
4
投票

您希望-被解释为连字符,而不是减号,因此请将其包含在字符串部分中。然后用*将字符串连接到斜体,~将符号放在彼此旁边,而不是library(ggplot2) ggplot(data.frame()) + labs(x = expression("Proportion of"~italic(n)*"-gram Model"~(1-gamma))) ,它留下空间。

另一方面,(1-γ)应格式化为数学。

?plotmath

qazxswpoi的文件。

© www.soinside.com 2019 - 2024. All rights reserved.