用奇异的xvalue绘制的ggpubr ggbarplot

我使用以下CSV代码获取以下代码

library(ggpubr)
library(ggsci)
df = read.csv2("file.csv",row.names=1)
# Copy df
df2 = df
# Convert the cyl variable to a factor
df2$perc <- as.factor(df2$perc)
# Add the name colums
df2$name <- rownames(df)
ggbarplot(df2,x = "name",y = "perc",fill = "role",# change fill color by cyl
          color = "white",# Set bar border colors to white
          palette = "npg",# jco journal color palett. see ?ggpar
          sort.val = "asc",# Sort the value in dscending order
          sort.by.groups = FALSE,# Don't sort inside each group
          x.text.angle = 0,# Rotate vertically x axis texts
          rotate = TRUE,label = TRUE,label.pos = "out",#label = TRUE,lab.pos = "in",lab.col = "white",width = 0.5
)

CSV为:

genes;perc;role
GATA-3;7,9;confirmed in this cancer
ccdC74A;6,8;prognostic in this cancer
LINC00621;6,1;none
POLRMTP1;4,1;none
IGF2BP3;3,2;confirmed in this cancer

产生了这个情节

用奇异的xvalue绘制的ggpubr ggbarplot

我在这里没有两件事:

1)为什么每个条的x轴刻度都与绘制的实际值相对应?我的意思是为什么x轴不是从0到8,我认为应该如此。我希望我能正确解释。

2)标签值似乎与y厚度不对齐。我在这里缺少选项吗?

tianlong253 回答:用奇异的xvalue绘制的ggpubr ggbarplot

说实话,我可能不会在这里使用ggpubr。保持ggplot语法通常更安全。而且可以说是更少的代码... (此外,如用户teunbrand所说,在这种情况下请不要使用因素)

水平条有两个不错的选择

library(tidyverse)
library(ggstance)
library(ggsci)

选项1 -使用coord_flip

ggplot(df2,aes(fct_reorder(genes,perc),perc,fill = role)) +
  geom_col() +
  geom_text(aes(label = perc),hjust = 0) +
  scale_fill_npg() +
  coord_flip(ylim = c(0,100)) +
  theme_classic() +
  theme(legend.position = 'top') +
  labs(x = 'gene',y = 'percent')

选项2-使用ggstance软件包 我更喜欢选项2,因为使用ggstance可以与其他图更灵活地组合

ggplot(df2,aes(perc,fct_reorder(genes,fill = role)) +
  geom_colh() +
  geom_text(aes(label = perc),hjust = 0)+
  scale_fill_npg() +
  coord_cartesian(xlim = c(0,100)) +
  theme_classic() +
  theme(legend.position = 'top')+
  labs(x = 'gene',y = 'percent')

reprex package(v0.3.0)于2020-03-27创建

数据

df2 <- read_delim("genes;perc;role
GATA-3;7,9;confirmed in this cancer
CCDC74A;6,8;prognostic in this cancer
LINC00621;6,1;none
POLRMTP1;4,1;none
IGF2BP3;3,2;confirmed in this cancer",";") %>% rownames_to_column("name")
本文链接:https://www.f2er.com/2567890.html

大家都在问