Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reverse point size in ggplot?

Tags:

r

ggplot2

Please, help me with this point. I need the positive values to be represented as small points and negative as large points. If I tape minus before size, the point sizes are right but the legend is changing:

df=data.frame(x=rnorm(20),y=runif(20),z=rnorm(20))
ggplot(df,aes(x=x,y=y))+geom_point(aes(size=-z))

so that does not suite.

like image 495
O_Devinyak Avatar asked Jan 13 '13 19:01

O_Devinyak


People also ask

How do I change the size of the dots in ggplot2?

To change the size of dots in dotplot created by using ggplot2, we can use binwidth argument inside geom_dotplot.

What does geom_point () do in R?

The function geom_point() adds a layer of points to your plot, which creates a scatterplot.

What is Geom_count?

geom_count is a variant of geom_point that counts the number of observations at each location, then maps the count to point area. It is useful when you have discrete data with overplotting.


1 Answers

Little late, but an easier way would just to add trans='reverse' to scale_size.

Example:

df=data.frame(x=rnorm(20),y=runif(20),z=z=(-13:6))
ggplot(df,aes(x=x,y=y))+
geom_point(aes(size=z)) +
scale_size(trans = 'reverse')

example plot with reversed size scale

like image 169
charlie Avatar answered Sep 24 '22 04:09

charlie