I am struggling with adjusting the point size in geom_point(). I have read through several questions on SO, but haven't found an answer that solved my issue.
I would like the size of the points generated by geom_point() to always have the same size, in terms of units on the x and y-axis, regardless of the size of plot or limits of the x and y-axis.
an example:
library(tidyverse)
tribble(
~object, ~x, ~y, ~group, ~size,
"head", 100, 180, 1, 10,
"neck", 100, 160, 1, 3,
"pelvis", 100, 100, 1, 3,
"lhip", 90, 90, 2, 3,
"rhip", 110, 90, 3, 3,
"lfoot", 50, 0, 2, 3,
"rfoot", 150, 0, 3, 3,
"lshoulder", 85, 155, 4, 3,
"rshoulder", 115, 155, 5, 3,
"lhand", 75, 100, 4, 3,
"rhand", 125, 100, 5, 3) %>%
ggplot(aes(x, y, group = group, color = as.factor(group)))+
geom_point(aes(size=size))+
geom_path()+
coord_equal()+
xlab("cm")+
ylab("cm")+
theme(legend.position = "none")+
scale_radius(range = c(4, 15))
This looks fine, but if I change e.g. the limits of the axis the point size becomes distorted, e.g., we can add another person standing 10 m away.
tribble(
~object, ~x, ~y, ~group, ~size,
"head", 100, 180, 1, 10,
"neck", 100, 160, 1, 3,
"pelvis", 100, 100, 1, 3,
"lhip", 90, 90, 2, 3,
"rhip", 110, 90, 3, 3,
"lfoot", 50, 0, 2, 3,
"rfoot", 150, 0, 3, 3,
"lshoulder", 85, 155, 4, 3,
"rshoulder", 115, 155, 5, 3,
"lhand", 75, 100, 4, 3,
"rhand", 125, 100, 5, 3,
#Person two
"head", 1500, 180, 6, 10,
"neck", 1500, 160, 6, 3,
"pelvis", 1500, 100, 6, 3,
"lhip", 1490, 90, 7, 3,
"rhip", 1510, 90, 8, 3,
"lfoot", 1450, 0, 7, 3,
"rfoot", 1550, 0, 8, 3,
"lshoulder", 1485, 155, 9, 3,
"rshoulder", 1515, 155, 10, 3,
"lhand", 1475, 100, 9, 3,
"rhand", 1525, 100, 10, 3) %>%
ggplot(aes(x, y, group = group, color = as.factor(group)))+
geom_point(aes(size=size))+
geom_path()+
coord_equal()+
xlab("cm")+
ylab("cm")+
theme(legend.position = "none")+
scale_radius(range = c(4, 15))
Is there some way I can set the point size to an absolute value measured in either the x or y-axis or both of them? Let's say I would like the head always to have a radius of 10 cm, and the remaining points to have a radius of 3 cm.
I understand that this is not the common usage of ggplot, but I imagine the same issue can arise if someone is plotting a map and size of the points needs reflect an actual area of the map. Is there perhaps some other trick I can use to get around this issue?
Any advice or help is much appreciated.