首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将绘图翻转90度

如何将绘图翻转90度
EN

Stack Overflow用户
提问于 2020-09-04 20:19:37
回答 1查看 93关注 0票数 0

我有以下图

我想把它翻转90度,这样看起来就像这样

以下是当前绘图的代码:

代码语言:javascript
复制
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(),但它不起作用。我还尝试将代码更改为:

代码语言:javascript
复制
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

但是我得到了一个错误:

代码语言:javascript
复制
position_stackv requires non-overlapping y intervals 

我认为答案介于两者之间!

感谢您的帮助!

代码语言:javascript
复制
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"))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-04 20:45:35

似乎您需要将所有xy%s互换,反之亦然。包含到geom_hlinegeom_vline

代码语言:javascript
复制
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))

使用您提供的数据,以下是输出:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63741060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档