Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206126

Change order of subplots

$
0
0

Is there a way to change the order of subplots in plotly for R? Is there a way to manually change the levels of a factor in this code? I want a plot with Weight in the first plot followed by a,b,c in order above it. But what I get as output is Weight, c, a and b as shown in the image graph

Here is my code

df<-data.frame("time"= seq(0.01,10,length.out=100),"Weight"=1:100, "a"=rnorm(100),"b"=rnorm(100),"c"=rnorm(100))

q <- df%>%
  tidyr::gather(variable, value, -time) %>%
  transform(id = as.integer(factor(variable))) %>%
  plot_ly(x = ~time, y = ~value, color = ~variable, colors = "Dark2",
          yaxis = ~paste0("y", id)
          ) %>%

 layout(
  xaxis = list(title = "Time,s",tickfont = list(size = 17),titlefont = list(size = 20)),
  yaxis = list(tickfont = list(size = 17), title="DP"),
  hoverlabel = list(font=list(size=20))
) %>% 
  add_lines() %>%
  subplot(nrows = length(df)-1, shareX = TRUE)

enter image description here


Viewing all articles
Browse latest Browse all 206126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>