[英]How do I produce a plot in landscape [rotated by 90 degrees] orientation in knitr?
[英]How to flip a plot 90 degrees
这是当前情节的代码:
library(tidypaleo)
library(tidyverse)
theme_set(theme_bw(8))
regforamcounts<-pivot_longer(regforamcounts,cols=c(-Sample,-SWLI,-Site), names_to="species",
values_to = "rel_abund")
regforamcounts$Site <- as.character(regforamcounts$Site)
P1<-ggplot(regforamcounts, aes(x = SWLI, y = rel_abund,group=1,fill=Site)) +
geom_col(position="identity",width=0.5) +
facet_abundance(vars(species)) +
labs(x = "SWLI (m)", y = "Relative abundance")+
theme(panel.grid.major = element_blank())+
theme(panel.grid.minor = element_blank())+
scale_fill_manual(values=c("#01216D","#5C95B8","#DAA585"))+geom_vline(xintercept =c(200,100))
P1
我曾尝试使用 coord_flip() 但它不起作用。我也尝试将代码更改为:
p1 <- ggplot(regforamcounts, aes(x = rel_abund, y = SWLI,fill=Site)) +
geom_colh(width=0.15) +
scale_y_reverse() +
facet_abundanceh(vars(species)) +
labs(x = "Relative abundance (%)", y = "SWLI (m AHD)")
p1
但我收到错误:
position_stackv requires non-overlapping y intervals
我认为答案介于两者之间!
感谢任何帮助!
structure(list(Sample = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("LG1",
"LG120", "LG130", "LG135", "LG160", "LG170", "LG185", "LG2",
"LG225", "LG230", "LG240", "LG245", "LG255", "LG260", "LG275",
"LG280", "LG285", "LG290", "LG295", "LG3", "LG305", "LG315",
"LG32", "LG36", "LG38", "LG4", "LG48", "LG5", "LG60", "LG7",
"LSP010", "LSP020", "LSP030", "LSP040", "LSP050", "LSP060", "LSP070",
"LSP080", "LSP089", "LSP100", "LSP110", "LSP120", "LSP130", "LSP140",
"LSP150", "LSP160", "LSP165", "ST-2LG0", "ST-2LG100", "ST-2LG120",
"ST-2LG140", "ST-2LG160", "ST-2LG190", "ST-2LG40", "ST-2LG60",
"ST-2LG80", "T3LB11.301", "T3LB12.05", "T3LB12.844", "T3LB13.87",
"T3LB14.51", "T3LB14.63", "T3LB15.321", "T3LB15.59", "T3LB15.95",
"T3LB16.69", "T3LB18.226", "T3LB19.762", "T3LB21.078", "T3LB26.256",
"T3LB28.57", "T3LB28.84", "T3LB29.03", "T3LB31.056", "T3LB31.365",
"T3LB7.008", "T3LB7.18", "T3LB7.303", "T3LB7.5", "T3LB7.9", "T3LB8.73",
"T3LB9.45", "WAP 0 ST-2", "WAP 10 ST-2", "WAP 110 ST1", "WAP 120 ST-1",
"WAP 122 ST-1", "WAP 125 ST1", "WAP 130 ST1", "WAP 135 ST-1",
"WAP 140 ST-1", "WAP 144 ST-1", "WAP 150 ST-1 ", "WAP 155 ST-1",
"WAP 159 ST1", "WAP 160 ST-1", "WAP 170 ST-1", "WAP 175 ST 1",
"WAP 180 ST-1", "WAP 190 ST-1", "WAP 200 ST-1", "WAP 210 ST-1",
"WAP 230 ST-1", "WAP 240 ST-1", "WAP 25 ST-2", "WAP 40 ST-2",
"WAP 45 ST-2", "WAP 5 ST-2", "WAP 50 ST-2", "WAP 55 ST-2", "WAP 60 ST-1",
"WAP 60 ST-2"), class = "factor"), SWLI = c(177.4585635, 177.4585635,
177.4585635, 177.4585635, 177.4585635, 177.4585635), Site = c("1",
"1", "1", "1", "1", "1"), species = c("AT.salsa", "BH.wilberti",
"CT.irregularis", "DP.ipohalina", "E.macrescens", "FT.inflata"
), rel_abund = c(0, 0, 1.7, 0, 12.9, 83.6)), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
看来您需要将所有x
s 与y
s 进行切换,反之亦然。 包括geom_vline
到geom_hline
。
ggplot(regforamcounts, aes(y = SWLI, x = rel_abund,group=1,fill=Site)) +
geom_colh(position="identity",width=0.5) +
facet_abundanceh(vars(species)) +
labs(y = "SWLI (m)", x = "Relative abundance")+
theme(panel.grid.major = element_blank())+
theme(panel.grid.minor = element_blank())+
scale_fill_manual(values=c("#01216D","#5C95B8","#DAA585"))+
geom_hline(yintercept =c(200,100))
使用您提供的数据,这是输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.