I have measurements from several points to several points in an R
data.frame
that
I’d like to plot as bars using R
‘s plotly
, where each from
is split by its to
s, and these to
‘s are sorted in ascending order for each from
.
Here’s the data.frame
:
library(dplyr)
set.seed(1)
df <- expand.grid(paste0("g", 1:4),paste0("g", 1:6)) %>%
dplyr::rename(from=Var1, to = Var2) %>%
dplyr::mutate(dist = runif(24, 0, 1)) %>%
dplyr::filter(as.character(from) != as.character(to)) %>%
dplyr::arrange(from,dist)
This plotly
command doesn’t achieve the sorting of to
‘s that I want:
plotly::plot_ly(x=df$from,y=df$dist,split=df$to,color=df$to,type="bar")
Any idea if there is a way to get the to
s sorted for each from
?
If not, is there a ggplot2
way of achieving this?