I am using plotly with Rshiny to create a scatter plot with text labels. Below is a reproducible example:
library(ggplot2)
library(plotly)
dat <- data.frame(LongExpressionValue = rnorm(1:100),
LongMethylationValue = rnorm(1:100),
LongCopyNumberValue = rnorm(1:100))
rownames(dat) <- paste0('n',seq(1:100))
# ggplot
p <- ggplot(data = dat, aes(x = LongExpressionValue, y = LongMethylationValue)) +
geom_point(size = 2) + geom_smooth(method = lm) +
geom_text(aes(label = rownames(dat)), vjust=-1.5, size = 3)
# ggplotly
ggplotly(p)
This creates a plot like:
How do I adjust my geom_text options so that the labels appear above and not overlapping the points? I do want to retain my ggplot code for it to be used across applications.
Thanks!
ggplot2
and not callplot_ly
directly? I find the solutions for those to be much easier, configs are all just lists of lists etc.. Specifically, the reference page on plotly's site allows positioning of all parts, and the hoverinfo and text options are amazing – Shapeaes_string
instead ofaes
? – Komal Rathias.name
if I need to work with programmatically-generated plots – Shape