我已经制作了一个图表,facet_grid
用于显示每天每个治疗组中每个组中的litium百分比.
library(ggplot2)
library(Rmisc)
library(plyr)
mus2 <- summarySE(mus, measurevar="litium",
groupvars=c("treatment", "group", "day"), na.rm = TRUE)
mus2
mus3 <- mus2
mus3$group <- factor(mus3$group)
ms.chl<- ggplot(mus3, aes(x=group, y=litium, fill=treatment)) +
geom_bar(stat="identity", colour="black") + facet_grid(~day) + theme_bw()
ms.chl
Run Code Online (Sandbox Code Playgroud)
结果如下:
为此我有两个问题:
我无法为litium内容PER GROUP制作正确的误差线.我试过这个,但每次治疗我只得到误差棒.
ms.chl + geom_errorbar(aes(ymin=litium-se, ymax=litium+se), size=0.5,
width=.25,
position=position_dodge(.9)) +
facet_grid(~day)
Run Code Online (Sandbox Code Playgroud)
我想从每组的总数中得到误差线
之后,我的第二个问题是:是否有可能代表每组的绝对值和每种治疗的百分比?
数据集(mus):
litium group treatment day
0.009439528 1 Control day1
0.005115057 1 Control day1
0.009742297 1 Control day1
0.016515625 2 Control day1
0.01074537 2 Control day1
0.016300836 2 Control day1 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 ggplot2 在 R 中的条形图上绘制误差条。条形的位置没问题,但是误差条未对齐、重叠。请看下面的例子:
library(ggplot2)
df = structure(list(variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,
4L, 4L), .Label = c("Stage1", "Stage2", "Stage3", "Stage4"), class = "factor"),
scenario = c("A", "A", "A", "B", "B",
"B", "A", "A", "A", "B", "B",
"B", "A", "A", "A", "B", "B",
"B", "A", "A", "A", "B", "B",
"B"), Period = c("2011-2040", "2041-2070", "2071-2100",
"2011-2040", "2041-2070", "2071-2100", "2011-2040", "2041-2070",
"2071-2100", …
Run Code Online (Sandbox Code Playgroud) 是否可以仅更改误差线的透明度?使用plt.errorbar()
更改的Alpha值会同时影响标记和误差线。
编辑:
就我而言,我有几个不同的数据集,每个值都有其自己的误差,因此我使用来绘制每个数据集plt.errorbar()
。这是使用3个不同数据集的MWE:
import matplotlib.pyplot as plt
import numpy as np
x1 = [np.random.uniform(0,10,5)]
x2 = [np.random.uniform(0,10,5)]
x3 = [np.random.uniform(0,10,5)]
y1 = [np.random.uniform(0,10,5)]
y2 = [np.random.uniform(0,10,5)]
y3 = [np.random.uniform(0,10,5)]
err1 = [np.random.uniform(1,2, 5)]
err2 = [np.random.uniform(1,2, 5)]
err3 = [np.random.uniform(1,2, 5)]
plt.errorbar(x1, y1, xerr=err1, yerr=err1, fmt='ro', ms=10)
plt.errorbar(x2, y2, xerr=err2, yerr=err2, fmt='bs', ms=10)
plt.errorbar(x3, y3, xerr=err3, yerr=err3, fmt='g^', ms=10)
plt.show()
Run Code Online (Sandbox Code Playgroud) 我想+facet_grid(.~sample,scales = "free_x")
在我的代码的最后一行强制刻面,但结果看起来很不美观(参见图 2)(以我的拙见)。我想知道是否有一种方法可以为 geom_histogram 的每个条形强制特定大小,以便无论组是否平衡,条形在组之间看起来都一样。
谢谢,薇薇安
样本数据 :
samplenote prod N mean sd se sampleprod sample
Sample A PRODUCT A 3 0.562103162 0.120039901 0.069305069 Sample A PRODUCT A Sample A
Sample A PRODUCT B 3 0.516322045 0.039250354 0.022661203 Sample A PRODUCT B Sample A
Sample B PRODUCT A 3 0.504789098 0.055005623 0.031757511 Sample B PRODUCT A Sample B
Sample B PRODUCT B 3 0.564334594 0.035685751 0.020603178 Sample B PRODUCT B Sample B
Sample C PRODUCT A 3 …
Run Code Online (Sandbox Code Playgroud) 我使用 pythonerrorbar
绘制了一个图,但是参数markersize
只能是标量而不是数组,这意味着所有数据点都具有相同的标记大小。我想知道如何markersize
为不同的数据点分配不同的值?
ax.errorbar(x,y,xerr=[xlow,xup],yerr=[ylow,yup],color='r',ls='None',marker='o',markersize=5.)
Run Code Online (Sandbox Code Playgroud)
如果我将标记大小创建为5.0*y
,我该如何使其工作?
大家好,
我输入数据为:
x(1),y(2),z(2)
x(2),y(2),z(2)
等等,
其中 x 和 y 值分别位于 x 轴和 y 轴上,z 值是误差线。从 Gnuplot 中,我如何重现图中多个图的误差条是透明的?
任何的想法?谢谢!
我试图用 Matplotlib 绘制误差条,就像附加的图形一样,我做不到,有什么建议吗?
import numpy as np
import matplotlib.pyplot as plt
Media = data["Media"]
Periodo = data["Periodo"]
P10th = data["P10th"]
P90th = data["P90th"]
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars: can also be len(x) sequence
fig, ax = plt.subplots()
ax.errorbar(Media, P90th, P10th, color='red', ls='--', marker='o', capsize=5, capthick=1, ecolor='black')
plt.xticks(ind, ('1910-1940', '1950-1990', '1990-2000', '2001-2010') )
ax.set_ylim(ylims)
Run Code Online (Sandbox Code Playgroud)
这是我的输出
errorbar ×7
ggplot2 ×3
r ×3
matplotlib ×2
python ×2
2d ×1
alignment ×1
bar-chart ×1
facet-grid ×1
gnuplot ×1
histogram ×1
marker ×1
python-2.7 ×1
transparency ×1