![](/img/trans.png)
[英]How do you increase the space between the axis labels and axis titles in R using functions ggplot() and plot_ly?
[英]Why aren't axis titles and labels showing up in base R when using plot()?
我正在尝试运行plot()
,但无法在 x 或 y 轴上显示默认轴标签或标题。 上次我运行这段代码时,它工作得很好。 R 和 R Studio 都在上个月更新了,我尝试关闭并重新启动 R Studio。 我自己的数据和内置数据(例如 iris 数据集)都有同样的问题。 如您所见,在不抑制轴标签和标题的情况下,没有按物种将轴标签和标题添加到萼片长度的 plot 中。
plot(iris$Species, iris$Sepal.Length)
我认为看不到轴标签和标题是一个更大问题的症状,因为我也很难使用title(ylab="Sepal Length", line=2.5, cex.lab=1, family = "Calibri Light")
。 代码运行没有错误并且没有 label 出现(如果我没有指定字体系列),或者我收到错误消息font family not found
。 我尝试添加extrafonts
并使用我知道安装在 package 中的 fonts,但无论如何我都会收到此错误。 似乎有些东西阻止我将任何文本添加到基础 R 图中。 任何见解将不胜感激。
我以前遇到过这种情况,我认为这只是 R 工作室中的一个错误。 单击显示清除所有图(小扫帚)的按钮,它应该按照样本数据的预期执行。
谢谢 - 我遇到了同样的问题,但“扫帚”对我不起作用。
但我确实确认这似乎是 RStudio 问题,因为当我将 output 转移到不同的图形设备时,文本就在那里。
这是我正在尝试的 MWE:
library(extrafont)
#font_import(pattern = 'calibri')
#Works fine
dev.off()
plot(1,1)
text(1, 1, "Hello World", pos = 1)
# Specify Calibri through par
dev.off()
par(family = fonts()[1])
plot(1,1)
text(1, 1, "Hello World", pos = 1)
# No text, no axes
text(1, 1, "Hello World", pos = 1)
# a second call is not a solution
text(1, 1, "Hello World", pos = 1, cex = 0.7)
# is cex a solution - still no axes
axis(1, cex = 5) #not printing regardless of cex
mtext(1, text = 'Hello World') #and mtext doesn't print either
我在Mac OS 11.2.1
上遇到了同样的问题; R 4.0.3
重新启动 R Session 内 Z0040CD1E256CD59F8106ZAF5 没有解决。 关闭 Rstudio 并重新启动并没有解决它。 启动实际的 R 应用程序并没有解决它。 我终于重新启动了我的机器,然后一切正常。
我最初在使用dev.copy(png, file="xxx.png"); dev.off()
后遇到了问题。 dev.copy(png, file="xxx.png"); dev.off()
但现在当然可以正常工作。 所以更多的信息,但我认为它不会最终“解决”这个问题。 对不起。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.