Reputation: 53
Consider custom dataset:
# install.packages('mvtnorm')
library(mvtnorm)
x1 = cbind(rmvnorm(20, mean = c(0, 0), sigma = matrix(c(0.35, 0, 0, 0.35), nrow = 2)), rep(1, 20))
x2 = cbind(rmvnorm(20, mean = c(0, 4), sigma = matrix(c(0.5, 0.24, 0.24, 0.5), nrow = 2)), rep(2, 20))
x3 = cbind(rmvnorm(20, mean = c(3.5, 2.8), sigma = matrix(c(0.4, -0.21, -0.21, 0.8), nrow = 2)), rep(3, 20))
x4 = cbind(rmvnorm(20, mean = c(3, -3.2), sigma = matrix(c(0.3, 0.2, 0.2, 0.8), nrow = 2)), rep(4, 20))
x5 = cbind(rmvnorm(20, mean = c(-0.6, -4), sigma = matrix(c(0.8, 0.1, 0.1, 0.15), nrow = 2)), rep(5, 20))
x6 = cbind(rmvnorm(20, mean = c(-3, 0.2), sigma = matrix(c(0.3, 0, 0, 1), nrow = 2)), rep(6, 20))
df = rbind(x1, x2, x3, x4, x5, x6)
colnames(df) = c("x", "y", "class")
df = data.frame(df)
df$class = as.factor(df$class)
Then I am trying to plot it as a scatter plot using ggplot
.
library(ggplot2)
ggplot(df) +
geom_point(aes(x = x, y = y, color = class, shape = class))
As the points are too small I would like to enlarge them a bit:
ggplot(df) +
geom_point(aes(x = x, y = y, color = class, shape = class, size = 2))
When I am trying other sizes, i.e. size = 3
or size = 2137
I still get the points of this size, no matter what I pass as size
parameter.
ggplot(df) +
geom_point(aes(x = x, y = y, color = class, shape = class, size = 2137))
How to correctly set the points size? Am I missing something?
Upvotes: 0
Views: 882
Reputation: 78907
As dear @teunbrand has stated in the comments: use size
outside aes()
ggplot(df, aes(x = x, y = y, color = class, shape = class)) +
geom_point(size = 20)
Upvotes: 1