Hello everyone specially all R programmer, I need your kind help. I am trying to make scatter plot with std error bar![enter image description here][1] but i couldn't manage it. Till now I can make scatter plot with labels and 45 degree angle line(which I need also). If anyone help me or add some code in my existing one that will be very much helpful for me.
My code
Dataset <- read.table("AvgDis.csv",header=TRUE, sep="",
na.strings="NA", dec=".",
strip.white=TRUE)
plot(Dataset$True,Dataset$False,
xlim=c(0,100), ylim=c(0,100),
main="Average % of disorder",
xlab="True", ylab="False",
pch=19,col= "blue")
text(Dataset$True,Dataset$False,
labels=Dataset$MotifId,
cex= 0.7, pos=3)
abline(0,1)
Data, I am using :
False True MotifId
54.1666675 33.33333 aps
35.2040825 48.57143 dbox
44.3055575 94.44444 ken
70.37037 60 mdm2
1.6666675 0 met
72.222225 100 ptk
46.9212975 68.51852 scftrcp1
55.5555575 70.83333 siah
First I'm going to create a fake data frame, because the way you've posted your data makes it inconvenient to copy and paste.
# Make a fake dataset since it is inconvenient to copy & paste the data you show
set.seed(13)
False <- rnorm(10, mean=50, sd=10)
True <- rnorm(10, mean=50, sd=10)
MotifId <- letters[1:10]
Dataset <- data.frame(False, True, MotifId)
You'll need to calculate the standard error somehow. Let's just imagine that all the data points have the same standard error:
Dataset$stderr <- 7 # This will recycle to the number of rows of Dataset
Now create your plot and add error bars as arrow
s, as suggested here
plot(Dataset$True,Dataset$False,
xlim=c(0,100), ylim=c(0,100),
main="Average % of disorder",
xlab="True", ylab="False",
pch=19,col= "blue")
text(Dataset$True,Dataset$False,
labels=Dataset$MotifId,
cex= 0.7, pos=3)
abline(0,1)
arrows(x0=Dataset$True, y0=Dataset$False - Dataset$stderr,
x1=Dataset$True, y1=Dataset$False + Dataset$stderr,
angle=90, code=3, length=0.05)
In the long term I think it is preferable to use the ggplot2
data visualization package
require(ggplot2)
# Build the plot from layers
p <- ggplot(Dataset, aes(x=True, y=False, label=MotifId)) +
geom_point() +
geom_text(, vjust=1, hjust=1) +
geom_errorbar(aes(ymin=False-stderr, ymax=False+stderr), width=1) +
geom_abline(slope=1, intercept=0) +
xlim(c(0, 100)) +
ylim(c(0, 100)) +
ggtitle("Average % of disorder") +
theme_bw()
print(p)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.