簡體   English   中英

如何在 plotrix 或 ggplot2 上 plot 3 y 軸 plot?

[英]How to plot 3 y-axes plot on plotrix or ggplot2?

我想 plot 在三個 Y 軸和一個 X 軸 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

“復制率”和“增長率”數據應顯示為(差異)彩色條形圖,而豐度數據應顯示為同一 plot 上的線 + 點 plot。 總共將有一個 X 軸和三個 Y 軸。 任何 R 代碼都將受到高度贊賞,一定會讓我開心!

您可能想嘗試plotly 我自己對此幾乎沒有經驗。 這是我嘗試過的,只是為了給你一些想法開始:

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")

數據:

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)
)

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM