ggplot scatterplot指向没有填充的点

时间:2021-02-15 23:36:38

I want to make a scatterplot whose points have no fill (or equivalently, with a transparent fill).

我想制作一个散点图,其点没有填充(或等效,透明填充)。

# generate some random data for the scatterplot
n <- 5
f <- factor(1:n)
df <- expand.grid(f1 = f, f2 = f)
df <- transform(df, v1 = round(10 * runif(n ** 2)))

# plot the scatterplot
ggplot(df) + geom_point(aes(x = f1, y = f2, size = v1, fill = NA))

Setting fill to NA seems logical but did not work. I also tried NULL and "" to no avail.

将填充设置为NA似乎合乎逻辑但不起作用。我也试过NULL和“”无济于事。

2 个解决方案

#1


14  

I think you want to play with shape but may be wrong:

我想你想玩形状但可能是错的:

ggplot(df) + geom_point(aes(x = f1, y = f2, size = v1), shape=1)

Or maybe...

ggplot(df) + geom_point(aes(x = f1, y = f2, size = v1), fill="green", shape=21)

if you want to fill a color.

如果你想填充颜色。

#2


0  

In the later versions of ggplot (ggplot2_3.0.0) you can do the following using any shape:

在ggplot(ggplot2_3.0.0)的更高版本中,您可以使用任何形状执行以下操作:

    ggplot(df) +
      geom_point(aes(x = f1, y = f2, size = v1)) +
      scale_shape(solid = FALSE)

#1


14  

I think you want to play with shape but may be wrong:

我想你想玩形状但可能是错的:

ggplot(df) + geom_point(aes(x = f1, y = f2, size = v1), shape=1)

Or maybe...

ggplot(df) + geom_point(aes(x = f1, y = f2, size = v1), fill="green", shape=21)

if you want to fill a color.

如果你想填充颜色。

#2


0  

In the later versions of ggplot (ggplot2_3.0.0) you can do the following using any shape:

在ggplot(ggplot2_3.0.0)的更高版本中,您可以使用任何形状执行以下操作:

    ggplot(df) +
      geom_point(aes(x = f1, y = f2, size = v1)) +
      scale_shape(solid = FALSE)