I am applying labels to a plot similar to this example. The labels would be the numeric value of the points on the line. They keep getting cut off. I am trying to figure out how to reliably adjust the y-axis limits so all labels fit in the plot window. I have not been able to find anything that works consistently. Thank you for your help!
library(ggplot2)
mymin <- -1000000
mymax <- -mymin
myinterval <- 100000
myseq <- seq(mymin,mymax,myinterval)
temp <- data.frame(X=myseq,Y=myseq,Name=rep("labels",length(myseq)))
p <- ggplot(temp,aes(x=X,y=Y)) + geom_line() +
geom_text(data=subset(temp,Y<0),aes(x=X,y=Y,label=Name),angle=90,hjust=1)+
geom_text(data=subset(temp,Y>0),aes(x=X,y=Y,label=Name),angle=90,hjust=0)+
scale_y_continuous(labels = scales::label_number_si())+
scale_x_continuous(labels = scales::label_number_si())
p
My session info:
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] scales_1.1.1 ggplot2_3.3.2