尺寸在geom_point中的真正含义是什么?

Jon*_*ein 11 r ggplot2

在这两个图中,这些点看起来不同,但为什么呢?

mya <- data.frame(a=1:100)

ggplot() +
  geom_path(data=mya, aes(x=a, y=a, colour=2, size=seq(0.1,10,0.1))) +
  geom_point(data=mya, aes(x=a, y=a, colour=1, size=1)) +
  theme_bw() +
  theme(text=element_text(size=11))

ggplot() +
  geom_path(data=mya, aes(x=a, y=a, colour=2, size=1)) +
  geom_point(data=mya, aes(x=a, y=a, colour=1, size=1)) +
  theme_bw() +
  theme(text=element_text(size=11))
Run Code Online (Sandbox Code Playgroud)

?aes_linetype_size_shape 解释......

 # Size examples
 # Should be specified with a numerical value (in millimetres),
 # or from a variable source
Run Code Online (Sandbox Code Playgroud)

但在我的代码中它看起来不同.

San*_*att 14

您的代码中发生了一些令人困惑的事情.您似乎以aes非预期的方式使用该功能.除了size问题,你得到了多个传说,我认为ggplot对颜色很困惑.

aes函数用于将美学映射到数据中的变量,但您正在使用它将美学设置为常量.此外,您正在使用该aes功能设置两个独立的美学.即使你设置size为常量,ggplot2也不喜欢两个独立的(路径和点)大小映射.此外,您还使用颜色映射执行相同操作.

sizecolour设置为常量值,因此将它们移到aes函数外部.此外,对于size第一个图中的路径,将size变量添加到数据帧可能更安全.(我已经修改了你的数据,以便可以看到点和路径.)正如预期的那样,绘制了第一个图中的一个图例.

    library(ggplot2)
mya <- data.frame(a=1:10, size = seq(10, 1, -1))

ggplot() +
  geom_path(data=mya, aes(x=a, y=a, size=size), colour = 2) +
  geom_point(data=mya, aes(x=a, y=a), colour = 1, size = 3) +
  theme_bw() +
  theme(text=element_text(size=11))

ggplot() +
  geom_path(data=mya, aes(x=a, y=a), colour = 2, size = 1) +
  geom_point(data=mya, aes(x=a, y=a), colour = 1, size = 3) +
  theme_bw() +
  theme(text=element_text(size=11))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述