[R] add error bars packet line chart: geom_path:. Each group consists of only one observation Do you need to adjust the ...

Want a simple packet line chart, and add error bars, similar to the following:
image.png
use can be achieved ggplot seems simple: ggplot+geom_errorbar+geom_line+geom_pointa focus on the calculation error bars.
It is to see sample data:
image.png
Type two transcription and protein proteomics, Region are different areas of an organization. It looks like as shown above, i.e., different regional distribution in the line graph of two genomics.

Calculating an error needs to be installed Rmisc package summarySE function.

# summarySE 计算标准差和标准误差以及95%的置信区间.
library(Rmisc)
tgc <- summarySE(df2, measurevar="Abundance", groupvars=c("Type","Region"))

Data becomes this:
image.png
The next step is mapping a.

# 带有标准误差线的折线图
# Standard error of the mean
ggplot(tgc, aes(x=Region, y=Abundance, colour=Type)) +   
  geom_errorbar(aes(ymin=Abundance-se, ymax=Abundance+se), width=.1) +
  geom_line() +
  geom_point()

Be warned:
image.png
chart is the case, the line is not drawn.
image.png
The answer checked the Internet under: https://blog.csdn.net/tanzuozhev/article/details/51106089
almost the same as mine its data form, but was able to draw out of the normal.

I thought, is not a grouping variable Type and Region did not set factor, but the design is still the same.

Check the next error, that is to map group, so group = 1. https://stackoverflow.com/questions/27082601/ggplot2-line-chart-gives-geom-path-each-group-consist-of-only-one-observation
I here provided two sets with a group = 1 or 2 obviously not, then the group is mapped to a variable:

ggplot(tgc, aes(x=Region, y=Abundance, colour=Type, group=Type)) +  
  geom_errorbar(aes(ymin=Abundance-se, ymax=Abundance+se), width=.1) +
  geom_line() +
  geom_point()

Really solved
image.png
, but I still do not understand why the Internet is also an example of two grouping variables, no group can do it.

Guess you like

Origin www.cnblogs.com/jessepeng/p/11443872.html