有没有办法在基数 R 的原点绘制单个原点符号?

Is there a way to plot a single origin symbol at the origin in base R?

我正在尝试在原点处绘制一个大写字母 O,但我该如何绘制该区域?

MWE:

par(mar = c(6, 6, 4, 3) + 0.1, mgp = c(4, 1, 0))
x <- c(0, 10)
y <- c(0, 10)
plot(x, y, axes = FALSE, xaxs = "i", yaxs = "i", type = "n", ylab = "")
mtext(expression(y), 2, 4, las = 1)
axis(1, 0:10, c("", 1:10))
axis(2, 0:10, c("", 1:10), las = 1)

根据评论 - 您要求的是基本 R 解决方案,但这里是使用 ggplot2 的相当直接的解决方案。不经常使用表达式,所以不太确定产生的警告。

这可能是 base R 绘图显示比 ggplot 更优雅的时刻之一,所以我也对 base R 解决方案很好奇。

下面的ggplot2解决方案有点不理想,因为你需要手动调整注释的位置。可能有一种更程序化的方法来找出其他标签的位置,通过挖掘 grobs,但我想这可能有点过头了。

library(ggplot2)
x <- y <- 0:10
mydat <- data.frame(x, y)

ggplot(mydat, aes(x, y)) +
  geom_point() +
  scale_x_continuous(expand = c(0, NA), breaks = 1:10) +
  scale_y_continuous(expand = c(0, NA), breaks = 1:10) +
  coord_cartesian(xlim = c(0, NA), ylim = c(0, NA), clip = "off") +
  annotate(geom = "text", x = -.2, y = -.2, label = expression(italic("O"))) +
  theme_classic()
#> Warning in is.na(x): is.na() applied to non-(list or vector) of type
#> 'expression'

reprex package (v0.3.0)

于 2021-01-30 创建

如果您想使用 R-base 试试这个:

plot(x, y, axes = FALSE, xaxs = "i", yaxs = "i", type = "n", ylab = "")
mtext(expression(italic('O')), side=1, line=0, at=0, adj = 1.5)
mtext(expression(y), 2, 4, las = 1)
axis(1, 0:10, c("", 1:10))
axis(2, 0:10, c("", 1:10), las = 1)