简体   繁体   English

无法使用ggplot2在R中绘制圆点

[英]Can't plot circular points in R using ggplot2

After experimenting with different point sizes and shapes when plotting with ggplot2, I found that I was no longer able to plot circular points. 在用ggplot2绘图时尝试不同的点大小和形状后,我发现我不再能够绘制圆点。 These simple examples illustrate the problem: 这些简单的例子说明了这个问题

# 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

Plot 1 output: 情节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

Plot 2 output: 图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

Plot 3 output: 图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

Plot 4 output: 图4输出:

在此输入图像描述

What do I have to do to plot circular points again? 我需要做些什么才能再次绘制圆形点? (I'm running R 3.1.3 and RStudio 0.98.1103 in Windows 7.) (我在Windows 7中运行R 3.1.3和RStudio 0.98.1103。)

It looks like it has to do with the limited resolution of the RStudioGD() graphics device. 它看起来与RStudioGD()图形设备的有限分辨率有关。 It becomes a non-issue by avoiding the RStudio interface: 通过避免RStudio接口,它成为一个非问题:

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

(from RStudio interface via save image) (来自RStudio界面,通过保存图片)

在此输入图像描述

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

在此输入图像描述

ggsave gives you more finely-tuned control over graphics parameters, including the height/width, dpi (for raster images, eg. png), and file format. ggsave为您提供更精细的图形参数控制,包括高度/宽度,dpi(对于光栅图像,例如png)和文件格式。 See the ?ggsave documentation for details. 有关详细信息,请参阅?ggsave文档。

Or alternatively, bump the geom_point up to size = 4 . 或者,将geom_point碰撞到size = 4

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM