ggplot在轴标签上的度数符号之前插入空格 [英] ggplot inserting space before degree symbol on axis label

查看:146
本文介绍了ggplot在轴标签上的度数符号之前插入空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在x轴上放置一个度数符号,但是结果有一个多余的空间,我似乎无法摆脱.文本应显示为温度(* C)",而不是温度(* C)".我尝试了两种不同的解决方案,但似乎无法摆脱空间.

I'd like to put a degree symbol on the x axis but the result has an extra space that I can't seem to get rid of. The text should read 'Temperature (*C)', not 'Temperature ( *C)'. I've tried two different solutions but can't seem to get rid of the space.

ggdat<-data.frame(x=rnorm(100),y=rnorm(100))

#neither of these approaches work
xlab <- expression(paste('Temperature (',~degree,'C)',sep=''))
xlab <- expression('Temperature ('*~degree*C*')')

ggplot(data=ggdat,aes(x=x,y=y)) +
  geom_point() +
  labs(x=xlab)

感谢您的帮助!

推荐答案

是否需要将xlabel用作表达式?您可以尝试直接将其粘贴.像这样的作品:

Do you need your xlabel to be an expression? You could try pasting it in directly. Something like this works:

set.seed(1)
ggdat<-data.frame(x=rnorm(100),y=rnorm(100))

xlab <- "Temperature (°C)"

ggplot(data=ggdat,aes(x=x,y=y)) +
  geom_point() +
  labs(x=xlab)

这篇关于ggplot在轴标签上的度数符号之前插入空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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