gpt4 book ai didi

r - 修改每个构面中的x轴标签

转载 作者:行者123 更新时间:2023-12-04 00:38:42 27 4
gpt4 key购买 nike

我有这张图表-我想在每个标签上添加文本N=xx来表示观察次数。我知道该怎么做,并且我已经在图表上做到了这一点。

当我在多面图表上尝试该按钮不起作用时,(我在所有3张图表的未平价报价中获得了相同的N,在“受限制”中获得了相同的N,依此类推)

我希望有人可以指出解决方案的方式,如何控制给定方面的元素?

library(ggplot2)
library(scales)

stat_sum_single <- function(fun, geom="point", ...) {
stat_summary(fun.y=fun, fill="red", geom=geom, size = 5, shape=24)
}

set.seed(1)
data1 <- data.frame(Physicians_In=sample(1:3,100,replace=T),Physicians_Out=sample(1:3,100,replace=T),share=runif(100,0,1))
data1$Physicians_In <- factor(data1$Physicians_In,levels=c(1,2,3),labels=c("Open","Restricted","Closed"))
data1$Physicians_Out <- factor(data1$Physicians_Out,levels=c(1,2,3),labels=c("Open","Restricted","Closed"))

access_ch3 <- ggplot(data1,aes(x=Physicians_In,y=share,fill=Physicians_In))+geom_boxplot()+stat_sum_single(mean)
access_ch3 <- access_ch3 +geom_jitter(position = position_jitter(width = .2),color="blue")+theme_bw()
access_ch3 <- access_ch3 + theme(legend.position="none") +scale_y_continuous("Gammagard Share",labels=percent)
gpo_labs5 <- paste(gsub("/","-\n",names(table(data1$Physicians_Out)),fixed=T),"\n(N=",table(data1$Physicians_Out),")",sep="")
access_ch3 <- access_ch3 + scale_x_discrete("Physician Access (In Hospital)",labels=gpo_labs5)
access_ch3 <- access_ch3 +facet_grid(.~Physicians_Out,labeller=label_both)
access_ch3


我尝试创建9个标签并将该矢量传递给 scale_x_discrete元素,该元素只是回收了前3个标签,因此它也无法解决问题。

最佳答案

这并不是您想要做的,但我认为这会有所帮助(至少是一个好的开始)

library(ggplot2)
library(plyr)
data1 <- ddply(data1,.(Physicians_Out,Physicians_In),transform,label = length(share))
ggplot(data1,aes(x=Physicians_In,y=share,fill=Physicians_In))+
geom_boxplot() +
stat_sum_single(mean) +
facet_grid(.~Physicians_Out,labeller=label_both,scales='free_x') +
stat_summary(fun.y=min,aes(label=paste0('N=',label)),geom='text',col='blue',cex=5)

关于r - 修改每个构面中的x轴标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20524630/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com