我正尝试使用HERE提供的脚本制作一个Y轴损坏的ggplot2 Barplot。
我的脚本
library(ggplot2)
dat <- read.csv("expression",header=T, check.names = FALSE)
dat
pd <- position_dodge(0.7) # move them .05 to the left and right
#Function to transform data to y positions
trans <- function(x){pmin(x,2) + 0.05*pmax(x-2,0)}
yticks <- c(0, 1, 2, 10,15,20,25,30)
#Transform the data onto the display scale
dat$mean_t <- trans(dat$value)
dat$sd_up_t <- trans(dat$value + dat$sd)
dat$sd_low_t <- pmax(trans(dat$value - dat$sd),1) #
png("test.png", units="in", family="Times", width=6, height=4, res=300) #pointsize is font size| increase image size to see the key
ggplot(data=dat, aes(x=gene, y=mean_t, group=treatment, fill=treatment)) +
geom_errorbar(aes(ymin=sd_low_t, ymax=sd_up_t),size=.5,
width=.2,
position=position_dodge(0.7)) +
geom_col(position="dodge") +
geom_rect(aes(xmin=0, xmax=4, ymin=2.2, ymax=2.3), fill="white") +
scale_y_continuous(limits=c(0,NA),expand = c(0,0), breaks=trans(yticks), labels=yticks) +
labs(y="Relative titer of CLas")+
theme_classic()
我的数据看起来像这样
gene,treatment,value,sd
tar1,EV,1,0.1
tar1,OX6,25.4,3
tar1,OX102,18.3,3
tar2,EV,1,0.1
tar2,OX6,1.6,0.2
tar2,OX102,1.5,0.2
tar3,EV,1,0.1
tar3,OX6,3.98,0.3
tar3,OX102,1.7,0.1
我遇到了3个问题
感谢您的帮助。