简体   繁体   English

为什么在使用 plot() 时轴标题和标签不显示在基础 R 中?

[英]Why aren't axis titles and labels showing up in base R when using plot()?

I'm trying to run plot() , and I can't get the default axis labels or titles to show up on either the x or y axes.我正在尝试运行plot() ,但无法在 x 或 y 轴上显示默认轴标签或标题。 The last time I ran this code, it worked just fine.上次我运行这段代码时,它工作得很好。 Both R and R Studio have been updated within the last month, and I've tried closing and restarting R Studio. R 和 R Studio 都在上个月更新了,我尝试关闭并重新启动 R Studio。 I have the same issue with both my own data and built in data, such as the iris data set.我自己的数据和内置数据(例如 iris 数据集)都有同样的问题。 As you can see, without repressing the axis labels and titles, no axis labels and titles are added to the plot of sepal length by species.如您所见,在不抑制轴标签和标题的情况下,没有按物种将轴标签和标题添加到萼片长度的 plot 中。

plot(iris$Species, iris$Sepal.Length)

在此处输入图像描述

I think not seeing axis labels and titles is a symptom of a larger issue, as I'm also having difficulty adding any labels or titles using commands like title(ylab="Sepal Length", line=2.5, cex.lab=1, family = "Calibri Light") .我认为看不到轴标签和标题是一个更大问题的症状,因为我也很难使用title(ylab="Sepal Length", line=2.5, cex.lab=1, family = "Calibri Light") Either the code runs without error and no label appears (if I don't specify font family), or I get an error message font family not found .代码运行没有错误并且没有 label 出现(如果我没有指定字体系列),或者我收到错误消息font family not found I've tried adding the extrafonts package and using fonts that I know are installed in that package, but I get this error regardless.我尝试添加extrafonts并使用我知道安装在 package 中的 fonts,但无论如何我都会收到此错误。 It seems there's something preventing me from adding any text to base R plots.似乎有些东西阻止我将任何文本添加到基础 R 图中。 Any insights would be much appreciated.任何见解将不胜感激。

I've encountered this before and I think it is just a bug in R studio.我以前遇到过这种情况,我认为这只是 R 工作室中的一个错误。 Click the button that says clear all plots (the little broomstick) and it should perform as expected with the sample data.单击显示清除所有图(小扫帚)的按钮,它应该按照样本数据的预期执行。

Thanks - I was having the same issue but the "broomstick" did not work for me.谢谢 - 我遇到了同样的问题,但“扫帚”对我不起作用。

But I did confirm that this seems to be RStudio issue as when I output to a different graphics device the text is there.但我确实确认这似乎是 RStudio 问题,因为当我将 output 转移到不同的图形设备时,文本就在那里。

Here's the MWE that I was trying:这是我正在尝试的 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

I encountered the same problem on Mac OS 11.2.1 ;我在Mac OS 11.2.1上遇到了同样的问题; R 4.0.3 Restarting R Session within RStudio did not solve it. R 4.0.3重新启动 R Session 内 Z0040CD1E256CD59F8106ZAF5 没有解决。 Shutting down Rstudio and restarting did not solve it.关闭 Rstudio 并重新启动并没有解决它。 Launching the actual R application did not solve it.启动实际的 R 应用程序并没有解决它。 I finally did a Restart of my machine, and then everything works fine.我终于重新启动了我的机器,然后一切正常。

I originally ran into the problem after I used dev.copy(png, file="xxx.png"); dev.off()我最初在使用dev.copy(png, file="xxx.png"); dev.off()后遇到了问题。 dev.copy(png, file="xxx.png"); dev.off() But now of course this works fine. dev.copy(png, file="xxx.png"); dev.off()但现在当然可以正常工作。 So some more information, but I don't think it will ultimately "solve" the issue.所以更多的信息,但我认为它不会最终“解决”这个问题。 Sorry.对不起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用函数 ggplot() 和 plot_ly 增加 R 中轴标签和轴标题之间的空间? - How do you increase the space between the axis labels and axis titles in R using functions ggplot() and plot_ly? 为什么在使用 plotstyle="ggplot" 时 qqcomp 函数中没有显示任何点? - Why aren't any points showing up in the qqcomp function when using plotstyle="ggplot"? 在基本r图中使用png()时,轴标签中的下标 - subscript in axis label when using png() in base r plot 使用R中的plot()在X轴上更改标签 - Change labels in X axis using plot() in R 轴标签未显示 - Axis labels not showing up R ggridges plot - 显示 y 轴刻度和标签 - R ggridges plot - Showing y axis ticks and labels R:为情节标题,轴标签或图例创建拉丁语/希腊语表达的向量 - R: creating vectors of latin/greek expression for plot titles, axis labels, or legends 在R中绘图-删除并重命名标题和标签 - plot in r - remove and rename titles and labels R plotly plot_ly函数:当我在项目内部调用plotly时,轴标题不出现 - R plotly plot_ly function: axis titles don't appear when I call plotly inside a project 使用plot()而不是lines()时,R中的线图中未显示的线 - lines not showing up on line graph in R when using plot() then lines()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM