Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.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
在geom_bar ggplot2中操作缩放y_日志_R_Ggplot2_Geom Bar - Fatal编程技术网

在geom_bar ggplot2中操作缩放y_日志

在geom_bar ggplot2中操作缩放y_日志,r,ggplot2,geom-bar,R,Ggplot2,Geom Bar,我以以下df为例: sites <- c('s1','s1','s2', "s2", "s3", "s3") conc <- c(15, 12, 0.5, 0.05, 3, 0.005) trop <- c("pp", "pt") df <- data.frame(sites, conc, trop) df$trop<- factor(df$trop, leve

我以以下df为例:

sites <- c('s1','s1','s2', "s2", "s3", "s3")
conc  <- c(15, 12, 0.5, 0.05, 3, 0.005)
trop  <- c("pp", "pt")

df <- data.frame(sites, conc, trop)
df$trop<- factor(df$trop, levels = c("pp", "pt"))

ggplot(df, aes(x= sites, y= conc))+
  geom_bar(stat = "identity", colour="black")+
  scale_y_log10()+
  facet_grid(.~trop)+
  theme_bw()

sites一个选项是将条形图重新参数化为矩形,并绘制矩形

库(ggplot2)
#>警告:包“ggplot2”是在R版本4.0.3下生成的

站点“我需要突出显示1和0.1以上的站点”是什么意思?如果您只需要安排两个绘图,请使用
patchwork
package:
库(patchwork);p1/p2
p1
为顶部图,
p2
为底部图)这是否回答了您的问题?当我有两个层次时,你的回答非常有用。然而,当
trop您可能想用%
操作中的
%in%
替换
=
操作时,我遇到了困难,因为如果两侧的变量长度不等或不是长度1,则无法对
=
操作进行矢量化。