Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symbol size in ggplot: scale_size_manual doesn't work

Tags:

r

ggplot2

I want to make some symbols in a figure bigger than the others. I found one solution, scale_size_manual, but it doesn't seem to have any impact.

Perhaps related, I also want to change the order of items in the legend. Again, the solution I found, guides(fill = guide_legend(reverse=TRUE), doesn't do anything.

#Fake data for this example
names <- c(rep("Other",8),rep("Porcupines",4),rep("Vipers",4), rep ("Pigs", 4))
rates <- runif(20, min=0, max=2)
sizes <- runif (20, min=0.1, max=5)
data <- data.frame (names, rates,sizes)

ggplot(data, aes(x=rates, y=sizes, group=names))+
    theme_classic(base_size = 14, base_family = "") +
    geom_point (aes(colour = names))+
    scale_colour_manual("Animal",values=c("blue","red", "green", "#0099FF"))+ 
    xlab ("Size")+
    ylab ("Rate")+
    scale_size_manual (values= c(1,2,2,2))+
    guides(fill = guide_legend(reverse=TRUE))

As mentioned above, the last two lines don't seem to be doing anything. Why not? Is there another way to change the symbol size of just some of the data (to make those points stand out)?

like image 423
David kirchman Avatar asked Feb 19 '15 18:02

David kirchman


1 Answers

I think you need to add size as an aethetic. Try aes(x=rates, y=sizes, group=names, size=names) and you'll see scale_size_manual() kick in.

like image 98
Andrew Avatar answered Oct 09 '22 08:10

Andrew