Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot scatterplot points with no fill

Tags:

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.

like image 342
David J. Avatar asked Mar 31 '13 06:03

David J.


People also ask

How do you make a point transparent in ggplot?

You can optionally make the colour transparent by using the form "#RRGGBBAA" . An NA , for a completely transparent colour.

What does %>% do in ggplot?

%>% is a pipe operator reexported from the magrittr package. Start by reading the vignette. Adding things to a ggplot changes the object that gets created. The print method of ggplot draws an appropriate plot depending upon the contents of the variable.

What does geom_point () do in R?

The function geom_point() adds a layer of points to your plot, which creates a scatterplot.


2 Answers

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.

like image 190
Tyler Rinker Avatar answered Sep 22 '22 19:09

Tyler Rinker


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

    ggplot(df) +
      geom_point(aes(x = f1, y = f2, size = v1, shape = v1)) +
      scale_shape(solid = FALSE)
like image 9
Gregory Avatar answered Sep 23 '22 19:09

Gregory