I would like to plot the values as in below example in a three Y-axes and one X-axis plot:
Name Replication ratio Growth rate Abundance(%)
Bin1 1.3 4.45 45
Bin2 1.2 5.66 12
Bin3 1.1 16.34 15
Bin4 1.5 11.45 3
Bin5 1.5 1.34 2
Bin6 1.9 2.37 32
The 'replication rate' and 'growth rate' data should appear as (differentially) colored bar plots whereas abundance data should appear as a line+dot plot on the same plot. In total there would be one X axis and three Y-axes. Any piece of R code would be highly appreciated and would certainly make my day!
You may want to try plotly
. I had little experience with it myself. This is what I have tried, just to give you some ideas to start with:
library(plotly)
plot_ly(data = df) %>%
add_lines(x = ~Names, y = ~Replication,
color = I("red"), name = "name01") %>%
add_markers(x = ~Names, y = ~Growth, yaxis = "y2",
color = I("blue"), name = "name02") %>%
add_bars(x = ~Names, y = ~Abundance, yaxis = "y3",
color = I("purple"), name = "name03") %>%
layout(
yaxis = list(showline = TRUE, side = "left", color = "red", title = "Replication rate"),
yaxis2 = list(showline = TRUE, overlaying = "y", anchor = "free", color = "blue", title = "Growth rate"),
yaxis3 = list(showline = TRUE, side = "right", overlaying = "y", color = "purple", title = "Abundance"),
xaxis = list(showline = FALSE, zeroline = FALSE, dtick = 1, title = ""),
showlegend = FALSE,
margin = list(pad = 50, b = 90, l = 150, r = 90),
legend = list(orientation = "h")
data:
df <- data.frame(
Names = c("Bin1", "Bin2", "Bin3", "Bin4", "Bin5", "Bin6"),
Replication = c(1.3, 1.2, 1.1,1.5,1.5,1.9),
Growth = c(4.45, 5.65, 16.34, 11.45, 1.34, 2.37),
Abundance = c(45, 12, 15, 3, 2, 32)
)
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.