Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
由2个y轴组成的多个并排条形图(ggplot或base R)_R_Ggplot2_Graphics_Bar Chart - Fatal编程技术网

由2个y轴组成的多个并排条形图(ggplot或base R)

由2个y轴组成的多个并排条形图(ggplot或base R),r,ggplot2,graphics,bar-chart,R,Ggplot2,Graphics,Bar Chart,具有2个y轴的多个并排条形图的说明 我想使用以下提供的数据,为两个变量生成一个条形图(见下文):- 一个用于T.max.open,它与open\u站点列一起 一个用于T.max.CAOPORY,它与_树下的列一起 x轴应命名为地形(即人工地表,裸土,草,凋落物和灌木丛,位于开阔地和树下的两列中) 每个地形组应该有两个相邻的条形图,代表不同植被类型在开阔地(开阔地)和树冠下(树木下)的温度范围 我不能使用一个y轴,因为我想显示树冠下方的温度(y轴1-T.max.canopy)和开放场地(y轴2-T

具有2个y轴的多个并排条形图的说明

我想使用以下提供的数据,为两个变量生成一个条形图(见下文):-

  • 一个用于T.max.open,它与open\u站点列一起
  • 一个用于T.max.CAOPORY,它与_树下的列一起
  • x轴应命名为地形(即人工地表裸土凋落物灌木丛,位于开阔地树下的两列中)
  • 每个地形组应该有两个相邻的条形图,代表不同植被类型在开阔地(开阔地)和树冠下(树木下)的温度范围

    我不能使用一个y轴,因为我想显示树冠下方的温度(y轴1-T.max.canopy)和开放场地(y轴2-T.max.open)之间的关系观察温度是否影响两种小气候中植物群落的大小和多样性

    条形图应该与我为另一个问题制作的(下图)相似。我就是想不出如何解决这个问题

    这是否适用于基本R(首选)

    如果有人能帮忙的话,谢谢你

    问题

    我曾尝试使用melt()和cast()等函数将数据格式化为正确的格式,但没有成功。我还在线搜索,从中找到了几种解决方案,但似乎不适用于我的情况。例如,两个堆栈溢出问题和

    数据

        structure(list(Under_Tree = structure(c(2L, 2L, 2L, 3L, 1L, 3L, 
        2L, 2L, 2L, 3L, 1L, 3L, 2L, 2L, 3L, 1L, 3L, 2L, 2L, 3L), .Label =      c("Artificial_Surface", 
        "Litter", "Undergrowth"), class = "factor"), Open_Site =      structure(c(2L, 
         3L, 1L, 3L, 2L, 2L, 2L, 2L, 3L, 1L, 3L, 2L, 2L, 3L, 1L, 3L, 2L, 
         2L, 3L, 1L), .Label = c("Artificial_Surface", "Litter",      "Undergrowth"
         ), class = "factor"), T.max.canopy = c(10, 14, 11.4, 7.7, 23.8, 
         12.9, 8, 15, 18.3, 9, 22.7, 12, 24.9, 11.2, 7.9, 4.5, 5.6, 13.7, 
         15.9, 16.4), T.max.open = c(8, 15, 18.3, 9, 22.7, 12, 17.4, 13, 
         17.9, 16.6, 14.6, 18.3, 27.5, 14.1, 17.5, 15.4, 13, 15.1, 15.1, 
          19.7)), .Names = c("Under_Tree", "Open_Site", "T.max.canopy", 
         "T.max.open"), class = "data.frame", row.names = c(NA, -20L))
    

    很抱歉,雨落在你的树冠上,但我觉得条形图并不是你美丽数据的最佳表现。在我看来,它们最好用散点图来表示,再加上刻面和颜色,故事就可以非常有效地讲出来。看看你是否同意:

    xy <- structure(list(Under_Tree = structure(c(2L, 2L, 2L, 3L, 1L, 3L, 
                                                  2L, 2L, 2L, 3L, 1L, 3L, 2L, 2L, 3L, 1L, 3L, 2L, 2L, 3L), .Label =      c("Artificial_Surface", 
                                                                                                                           "Litter", "Undergrowth"), class = "factor"), Open_Site =      structure(c(2L, 
                                                                                                                                                                                                     3L, 1L, 3L, 2L, 2L, 2L, 2L, 3L, 1L, 3L, 2L, 2L, 3L, 1L, 3L, 2L, 
                                                                                                                                                                                                     2L, 3L, 1L), .Label = c("Artificial_Surface", "Litter",      "Undergrowth"
                                                                                                                                                                                                     ), class = "factor"), T.max.canopy = c(10, 14, 11.4, 7.7, 23.8, 
                                                                                                                                                                                                                                            12.9, 8, 15, 18.3, 9, 22.7, 12, 24.9, 11.2, 7.9, 4.5, 5.6, 13.7, 
                                                                                                                                                                                                                                            15.9, 16.4), T.max.open = c(8, 15, 18.3, 9, 22.7, 12, 17.4, 13, 
                                                                                                                                                                                                                                                                        17.9, 16.6, 14.6, 18.3, 27.5, 14.1, 17.5, 15.4, 13, 15.1, 15.1, 
                                                                                                                                                                                                                                                                        19.7)), .Names = c("Under_Tree", "Open_Site", "T.max.canopy", 
                                                                                                                                                                                                                                                                                           "T.max.open"), class = "data.frame", row.names = c(NA, -20L))
    
    library(ggplot2)
    library(tidyr)
    library(Hmisc)
    
    xyg <- gather(xy, key = tree, value = microlocation, -T.max.canopy, -T.max.open)
    xyg <- gather(xyg, key = canopyside, value = temperature, -tree, -microlocation)
    
    ggplot(xyg, aes(x = microlocation, y = temperature, color = canopyside)) +
      theme_bw() +
      geom_point(alpha = 0.75) +
      scale_color_brewer(palette = "Set1") +
      stat_summary(fun.data = "mean_cl_boot", color = "black", size = 1, alpha = 0.5) +
      facet_wrap(~ tree)
    

    xy当值在同一范围内时,为什么需要两个y轴?因为T.max.open(开放场地的温度)和T.max.corporation(树冠下的温度)是两个独立的测量值,我想在同一个图上加以说明。因此,有可能检测到两种小气候中的温度变化之间的关系,以及变化的温度是否会影响检测到的植被类型的组成。如果你能帮忙,非常感谢