假設我有以下資料:
test = read.table(text = 'condition1 condition2 estimate std_error name
a x .466 .09 name_1
a y .343 .131 name_1
b x .466 .09 name_1
b y .343 .131 name_1
a x .466 .09 name_2
a y .343 .131 name_2
b x .466 .09 name_2
b y .343 .131 name_2', header = T, stringsAsFactors = T)
ggplot(data = test, aes(x = estimate, y = condition1, fill = condition2, group = condition2))
geom_point(color = 'black')
geom_linerange(aes(xmin = estimate - std_error,
xmax = estimate std_error), color = 'black')
ylab(NULL)
facet_grid(name ~ .,
scales = "free_y",
space = "free_y",
switch = 'y')

我試圖分離出x并y線作為內單獨的行b和a條件within給定的面(name_1和name_2)。但是我的代碼按原樣將兩行作為相同的 y 值,因此它們重疊。分隔線的最佳方法是什么?
uj5u.com熱心網友回復:
width = X根據口味調整。
...
geom_point(color = 'black', position = position_dodge(width = 1))
geom_linerange(aes(xmin = estimate - std_error,
xmax = estimate std_error), color = 'black',
position = position_dodge(width = 1))
...

或者在這里進行一些更多的美學調整:
ggplot(data = test, aes(x = estimate, y = condition1, fill = condition2, group = condition2))
geom_linerange(aes(xmin = estimate - std_error,
xmax = estimate std_error), color = 'black',
position = position_dodge(width = 0.5))
geom_point(color = 'black', size = 2, shape = 21, position = position_dodge(width = 0.5))
ylab(NULL)
facet_grid(name ~ .,
scales = "free_y",
space = "free_y",
switch = 'y')
theme(panel.grid.major.y = element_blank())

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/358879.html
上一篇:即使不在圖中也顯示圖例標記和標簽
