简体   繁体   中英

How to plot two X axes in R + Plotly + Shiny

I have three columns, Depth , Flow In , and Flow Out . I want to plot Flow In and Flow out against Depth . I want Depth to be on the Y axis whereas x1 to be Flow In and x2 to be Flow Out .

You may need to melt the dataframe using melt() from the reshape2 package. This would allow you to display the values side by side. You could use something like the following:

df.p <- ggplot(df, aes(x, value, fill = variable))
  df.p + 
    geom_bar(stat="identity",position="dodge") 
  })

Another thought, having no background on what your data is, you may consider a waterfall chart if you want to show depth as something always below the x-axis. You can use geom_rect for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM