Reputation: 376
I want to plot a data.frame, but on the legends the size is added. How do i control the size of the dots without adding size to the legends?
df1 <- data.frame(name = c("peter", "peter", "peter", "peter", "jacob", "jacob"),
test =c(10,8,4,2,7,5),
something =c(100,80,40,20,77,55)
)
df2 <- data.frame(name = c("Greg", "Lisa"),
test =c(11,3.5),
something =c(102,35)
)
ggplot(df1, aes(x=test, y=something, color= name,size = 3)) +
geom_point()+
geom_point(data=df2, aes(x=test, y=something, color= name, size=7))
Upvotes: 0
Views: 43
Reputation: 16910
You can just specify size
in geom_point()
itself:
library(ggplot2)
df <- data.frame(name = c("peter", "peter", "peter", "peter", "jacob", "jacob"),
test =c(10,8,4,2,7,5),
something =c(100,80,40,20,77,55)
)
ggplot(df, aes(x=test, y=something, color= name)) +
geom_point(size = 3)
In case you need all your point sizes to be 3 instead of just in this one call to geom_point()
, you can just update the default size:
ggplot(df, aes(x=test, y=something, color= name)) +
geom_point()
update_geom_defaults("point", list(size = 3))
ggplot(df, aes(x=test, y=something, color= name)) +
geom_point()
In the updated question, you can still specify size
per geom_point()
call, so long as you put it outside the aes()
wrapper:
ggplot(df1, aes(x=test, y=something, color= name)) +
geom_point(size = 3)+
geom_point(data=df2, aes(x=test, y=something, color= name), size=7)
Upvotes: 1