Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.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
R 如何改变刻面网格图的某些美学?_R_Ggplot2_Graph_Data Visualization_Facet Grid - Fatal编程技术网

R 如何改变刻面网格图的某些美学?

R 如何改变刻面网格图的某些美学?,r,ggplot2,graph,data-visualization,facet-grid,R,Ggplot2,Graph,Data Visualization,Facet Grid,我使用facet_grid和patchwork创建了这个图,因为我需要为每个参数定制一个二次y轴,它们都有不同的比例。我已经成功地调整了大部分美学,以符合我对图形的需求,除了几个地方: 与“站点”匹配颜色。我想分别将红色、蓝色和绿色与Port、Bluff和Palm匹配。它与我在scale\u color\u手册中的代码不兼容 重命名条带文本。我以前试过使用表达式(paste()),但不起作用,尤其是希腊字母。我希望每一行的右边都有这些各自的stip文本:ETR[max]、ψ和E[k]。 []中

我使用
facet_grid
patchwork
创建了这个图,因为我需要为每个参数定制一个二次y轴,它们都有不同的比例。我已经成功地调整了大部分美学,以符合我对图形的需求,除了几个地方:

  • 与“站点”匹配颜色。我想分别将红色、蓝色和绿色与Port、Bluff和Palm匹配。它与我在
    scale\u color\u手册
    中的代码不兼容
  • 重命名条带文本。我以前试过使用
    表达式(paste())
    ,但不起作用,尤其是希腊字母。我希望每一行的右边都有这些各自的stip文本:ETR[max]、ψ和E[k]。 []中的字母是下标 谢谢你的指点。这周我没有东西可以做了,尤其是脱衣舞文本

    我的数据帧:

    我的代码是:

    abrv_mo <- with (params, month.abb[month]) params <- transform(params, month = abrv_mo) params <- params[order(match(params$month, month.abb)), ] params$month <- factor(params$month, month.abb, ordered = TRUE) params$month<- as.Date(ISOdate(2019, as.numeric(params$month), 15))
    
    p1 <- ggplot() +   geom_hline(yintercept = 19.6, linetype = "dashed")
    +   geom_line(data = tmpr2, 
                aes(month, tmp*0.98), 
                alpha = 0.4) +   geom_errorbar(data = subset(params, variable == "max"),
                    aes(x= month, ymin = mean - se, ymax = mean +se, color = site),
                    width = 8) +   geom_point(data = subset(params, variable == "max"), 
                 aes(x=month, y=mean, color = site, group=site),
                 size = 2.5) +   facet_grid(rows = vars(variable),
                 cols = vars(site),
                 switch = "y", scale = "free_y") +   scale_x_date(name = NULL, date_labels = "%b", 
                   seq(as.Date("2019-01-15"), 
                       as.Date("2019-07-15"), by = "1 month")) + # ?strftime() for more options   scale_y_continuous(limits = c(5,40), breaks = seq(5, 40, by = 15),
                         expand = c(0,0), 
                         sec.axis = sec_axis(~./0.98)) +   scale_color_manual(name = "Site",
                        labels = c("Port", "Bluff", "Palm"),
                        values = c("#FC4E07","#00AFBB", "#C3D7A4")) +   theme_bw() +   theme(plot.background = element_blank(),
            strip.background = element_blank(),
            strip.placement = "outside",
            panel.grid.major = element_blank(),
            panel.grid.minor = element_blank(),
            panel.border = element_rect(size=1, colour = "black"),
            panel.spacing = unit(0.3, "lines"),
            axis.line = element_line(size=0.1, colour = "black"),
            axis.ticks.y = element_line(size=0.5, colour = "black"),
            axis.text.x = element_blank(),
            axis.text.y = element_text(size=10, color="black", margin = margin(t = 0.5, l = 0.5)),
            text = element_text(size = 18),
            legend.position="none",
            plot.margin=margin(l = -1, unit = "cm")) +   ylab(NULL)  
    
    p2 <- ggplot() +   geom_hline(yintercept = 0.16, linetype = "dashed")
    +   geom_line(data = tmpr2, 
                aes(month, tmp*0.008),
                alpha = 0.4) +   geom_errorbar(data = subset(params, variable=="slope"),
                    aes(x= month, ymin = mean - se, ymax = mean +se, color = site),
                    width = 8) +   geom_point(data = subset(params, variable == "slope"), 
                 aes(x=month, y=mean, color=site, group=site),
                 size = 2.5) +   facet_grid(rows = vars(variable),
                 cols = vars(site),
                 switch = "y",
                 scale = "free_y") +   scale_x_date(name = NULL, date_labels = "%b", 
                   seq(as.Date("2019-01-15"), 
                       as.Date("2019-07-15"), by = "1 month")) + # ?strftime() for more options   scale_y_continuous(breaks = seq(0.15,
    0.26, by = 0.05),
                         expand = c(0,0), 
                         limits = c(0.15,0.26),
                         sec.axis = sec_axis(~./0.008, name = "Temperature (°C)")) +   scale_color_manual(name = "Site",
                         labels = c("Port", "Bluff", "Palm"),
                         values = c("#FC4E07","#00AFBB", "#C3D7A4")) +   theme_bw() +   theme(plot.background = element_blank(),
            strip.background = element_blank(),
            strip.placement = "outside",
            strip.text.x = element_blank(),
            panel.grid.major = element_blank(),
            panel.grid.minor = element_blank(),
            panel.border = element_rect(size=1, colour = "black"),
            panel.spacing = unit(0.3, "lines"),
            axis.line = element_line(size=0.1, colour = "black"),
            axis.ticks.y = element_line(size=0.5, colour = "black"),
            axis.text.x = element_blank(),
            axis.text.y = element_text(size=10, color="black", margin = margin(t = 0.5, l = 0.5)),
            axis.text.y.right = element_text(size=10, color="black", margin = margin(t = 0.5, r = 10)),
            text = element_text(size = 18),
            legend.position="none",
            plot.margin=margin(l = -1.5, unit = "cm")) +   ylab(NULL)  
    
    p3 <- ggplot() +   geom_hline(yintercept = 140, linetype = "dashed") + geom_line(data = tmpr2, 
                aes(month, tmp*7),
                alpha = 0.4) +   geom_errorbar(data = subset(params, variable=="ek"),
                    aes(x= month, ymin = mean - se, ymax = mean +se, color = site),
                    width = 8) +   geom_point(data = subset(params, variable=="ek"), 
                 aes(x=month, y=mean, color=site, group=site),
                 size = 2.5) +   facet_grid(rows = vars(variable),
                 cols = vars(site),
                 switch = "y",
                 scale = "free_y") +   scale_x_date(name = NULL, date_labels = "%b", 
                   seq(as.Date("2019-01-15"), 
                       as.Date("2019-07-15"), by = "1 month")) + # ?strftime() for more options   scale_y_continuous(expand = c(0,0), 
                         breaks = seq(25, 250, by = 100),
                         limits = c(25,250),
                         sec.axis = sec_axis(~./7)) +   scale_color_manual(name = "Site",
                         labels = c("Port", "Bluff", "Palm"),
                         values = c("#FC4E07","#00AFBB", "#C3D7A4")) +   theme_bw() +   theme(plot.background = element_blank(),
            strip.background = element_blank(),
            strip.placement = "outside",
            strip.text.x = element_blank(),
            panel.grid.major = element_blank(),
            panel.grid.minor = element_blank(),
            panel.border = element_rect(size=1, colour = "black"),
            panel.spacing = unit(0.3, "lines"),
            axis.line = element_line(size=0.1, colour = "black"),
            axis.ticks.y = element_line(size=0.5, colour = "black"),
            axis.text.x = element_text(angle = 45,size=10, color="black", hjust = 1,
                                       margin = margin(t = 0.5, r = 0.5)),
            axis.text.y = element_text(size=10, color="black", margin = margin(t = 0.5, l = 0.5)),
            text = element_text(size = 18),
            legend.position="none",
            plot.margin=margin(l = -1.5, unit = "cm")) +   ylab(NULL) 
    
    library(patchwork) 
    p1 + p2 + p3 +   plot_layout(ncol = 1)
    

    abrv\u mo对于
    scale\u color\u手册
    中的颜色,您需要使用
    breaks
    参数<代码>标签
    将重新标记绘图。你需要
    scale\u color\u manual(name=“Site”,levels=c(“Port”,“Bluff”,“Palm”),value=c(“#FC4E07”,“#00AFBB”,“#C3D7A4”)
    (假设“Port”,“Bluff”和“Palm”)是你数据中的因子级别,我没有下载来检查)。至于条形文本,标签是个小问题。我认为,如果您创建一个最小的可复制示例,您可能会更快地获得帮助。它不要求人们下载文件,将其放入工作目录,将其加载到R中,转换日期列等。如果您(a)使用内置数据集,或(b)提出一个20行样本数据集,我们可以复制/粘贴(共享模拟代码或使用
    dput()
    复制对象),你会让人们更容易帮助你。它使这个问题成为更好的资源,以防你的驱动链接失效。