I am trying to make a marked portion of a bubble with ggplot2in R. Here is a simplified scenario:
I have a data frame with the 4 variables: 3 quantitative variables x, yand zwhile the other variable that refers to the point lab.
I want to create a scatter plot where the position is determined by xand y, and the size of the points is determined z. Then I want to place text labels next to the dots (for example, to the right of the dot) without overlapping the text on top of the dot.
If the points did not change in size, I could just change the aesthetics of the layer geom_textby adding a scaling constant (for example, aes(x=x+1, y=y+1)). However, even in this simple case, I have a problem with the correct position of the text, because the points do not scale with the output dimensions of the graph. In other words, the size of the points remains constant on the 500x500 and 1000x1000 sections - they do not scale with the dimensions of the plotted plot.
Therefore, I think that I need to scale the position of the label according to the size (for example, dimension) of the output graph, or I need to somehow get the radius of the points from ggplotand shift my text labels. Is there any way to do this in ggplot2?
Here is the code:
# Stupid data
df <- data.frame(x=c(1,2,3),
y=c(1,2,3),
z=c(1,2,1),
lab=c("a","b","c"), stringsAsFactors=FALSE)
# Plot with bad label placement
ggplot(aes(x=x, y=y), data=df) +
geom_point(aes(size=z)) +
geom_text(aes(label=lab),
colour="red") +
scale_size_continuous(range=c(5, 50), guide="none")
: , hjust vjust geom_text, .
ggplot(aes(x=x, y=y), data=df) +
geom_point(aes(size=z)) +
geom_text(aes(label=lab), hjust=0, vjust=0.5,
colour="red") +
scale_size_continuous(range=c(5, 50), guide="none")
EDIT: , , . , - .
, : , . . , (, - ) , . position_jitter, , .