Zoltan
Zoltan

Reputation: 782

How can point size be related to a transformed value, but have legend retain the original value?

Here I want the point area to be proportional to Petal.Width, so I set size as a function of sqrt(Petal.Width).

I'd like the legend to show circles for untransformed values of Petal Width (maybe 1, 2 , 3 and 4 ?)

library(ggplot2)
ggplot() +
 geom_point(data= iris, aes(x= Petal.Length, y = Petal.Width, size = sqrt(Petal.Width)))

enter image description here

Upvotes: 0

Views: 27

Answers (1)

Zoltan
Zoltan

Reputation: 782

turns out someone always solved this with scale_size_area()

library(ggplot2)

ggplot() +
  geom_point(data= iris, aes(x= Petal.Length, y = Petal.Width, size = Petal.Width)) + 
  scale_size_area()

enter image description here

Upvotes: 1

Related Questions