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.
You can optionally make the colour transparent by using the form "#RRGGBBAA" . An NA , for a completely transparent colour.
%>% 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.
The function geom_point() adds a layer of points to your plot, which creates a scatterplot.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With