【问题标题】:Can't plot circular points in R using ggplot2无法使用 ggplot2 在 R 中绘制圆形点
【发布时间】:2015-07-31 19:52:12
【问题描述】:

在使用 ggplot2 绘图时尝试了不同的点大小和形状后,我发现我不再能够绘制圆形点。这些简单的例子说明了这个问题:

# Plot 1 - square points (symbol #15) appear correctly
#
df = data.frame(x = c(1, 2, 3), y = c(4, 5, 6))
g1 <- ggplot(df, aes(x = x, y = y))
g1 <- g1 + geom_point(size = 3, shape = 15)
g1

绘图 1 输出:

# Plot 2 - circular points (symbol #16) appear as diamonds
#
df = data.frame(x = c(1, 2, 3), y = c(4, 5, 6))
g1 <- ggplot(df, aes(x = x, y = y))
g1 <- g1 + geom_point(size = 3, shape = 16)
g1

绘图 2 输出:

# Plot 3 - triangular points (symbol #17) appear correctly
#
df = data.frame(x = c(1, 2, 3), y = c(4, 5, 6))
g1 <- ggplot(df, aes(x = x, y = y))
g1 <- g1 + geom_point(size = 3, shape = 17)
g1

绘图 3 输出:

# Plot 4 - diamond points (symbol #18) appear correctly
#
df = data.frame(x = c(1, 2, 3), y = c(4, 5, 6))
g1 <- ggplot(df, aes(x = x, y = y))
g1 <- g1 + geom_point(size = 3, shape = 18)
g1

绘图 4 输出:

我该怎么做才能再次绘制圆形点? (我在 Windows 7 中运行 R 3.1.3 和 RStudio 0.98.1103。)

【问题讨论】:

  • 你是如何保存地块的?
  • 我还没有保存它们,只是从 RStudio 的 Plots 窗格中复制它们。
  • 在使用ggsave(g1, filename = "image.png")后尝试查看它们。

标签: r ggplot2 rstudio shape point


【解决方案1】:

这似乎与RStudioGD() 图形设备的有限分辨率有关。避免使用 RStudio 界面就不会成为问题:

g1 <- ggplot(df, aes(x = x, y = y))
g1 <- g1 + geom_point(size = 3)
g1

(从 RStudio 界面通过保存图像)

ggsave(g1, filename = "image.png")

ggsave 让您可以更精细地控制图形参数,包括高度/宽度、dpi(用于光栅图像,例如 png)和文件格式。有关详细信息,请参阅?ggsave 文档。

或者,将geom_point 提高到size = 4

【讨论】:

  • 就是这样 - 保存为文件时图形是正确的。谢谢!
猜你喜欢
  • 2023-03-22
  • 2014-06-28
  • 2020-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-13
  • 1970-01-01
相关资源
最近更新 更多