Character size in ggplot: scale_size_manual does not work

I want to make some characters on the figure more than others. I found one solution to scale_size_manual, but it does not seem to have any effect.

Perhaps related, I also want to reorder the elements in the legend. Again, the solution I found, the guides (fill = guide_legend (reverse = TRUE), do nothing.

#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 do not seem to do anything. Why not? Is there any other way to change the character size of only some data (to highlight these points)?

+4
source share
1 answer

I think you need to add size as aesthetic. Try aes(x=rates, y=sizes, group=names, size=names)it and you will see a scale_size_manual()blow.

+13
source

All Articles