我將此示例資料作為 CSV 讀入 R 資料幀
"TEST","PREVIOUS","LAST","Interaction"
0.592,0.689,0.708,"Insertion"
0.702,0.796,0.836,"Insertion"
0.687,0.738,0.738,"Circular permutation and repetition"
0.727,0.675,0.734,"Insertion"
0.944,0.919,0.925,"Insertion and conformational variability"
0.862,0.847,0.847,"Conformational variability"
0.808,0.763,0.827,"Insertion"
0.981,0.983,0.983,"Conformational variability"
0.703,0.786,0.788,"Circular permutation and conformational variability"
0.691,0.732,0.732,"Insertion and conformational variability"
0.659,0.641,0.655,"Insertion"
0.6,0.602,0.676,"Insertion and conformational variability"
0.355,0.704,0.707,"Circular permutation and insertion"
0.436,0.716,0.739,"Circular permutation and insertion"
0.386,0.677,0.699,"Circular permutation and insertion"
0.976,0.979,0.979,"Conformational variability"
0.73,0.757,0.757,"Circular permutation"
0.492,0.918,0.918,"Circular permutation"
0.688,0.672,0.685,"Circular permutation and insertion"
0.79,0.799,0.799,"Circular permutation"
0.756,0.817,0.834,"Circular permutation and insertion"
0.677,0.668,0.677,"Insertion"
0.892,0.884,0.89,"Conformational variability"
0.604,0.752,0.759,"Insertion and conformational variability"
0.589,0.721,0.73,"Insertion and repetition"
0.916,0.927,0.927,"Conformational variability and repetition"
0.665,0.667,0.667,"Insertion"
0.62,0.684,0.717,"Insertion"
0.683,0.714,0.714,"Circular permutation and conformational variability"
0.55,0.75,0.788,"Insertion"
0.584,0.67,0.704,"Insertion and repetition"
0.635,0.684,0.684,"Circular permutation"
0.45,0.605,0.623,"Insertion and conformational variability"
0.53,0.611,0.611,"Insertion"
0.792,0.778,0.811,"Insertion and repetition"
0.524,0.595,0.631,"Insertion"
0.591,0.719,0.771,"Insertion and conformational variability"
0.633,0.719,0.719,"Insertion"
0.785,0.803,0.816,"Insertion and repetition"
0.738,0.723,0.731,"Insertion and repetition"
然后我使用 ggplot 和以下代碼繪制下圖:
library(ggplot2)
fig = ggplot(dta, aes(x=LAST, y=TEST, fill=Interaction))
geom_point(
dta[which(dta["LAST"] == dta["PREVIOUS"]),],
mapping =aes(x=LAST,y=TEST),
shape=21, size=3,stroke = 0.25, alpha=0.9)
geom_point(
dta[which(dta["LAST"] != dta["PREVIOUS"]),],
mapping =aes(x=LAST,y=TEST),
shape=21, size=3, stroke = 0.25, alpha=0.9)
geom_point(
dta[which(dta["LAST"] != dta["PREVIOUS"]),],
mapping =aes(x=LAST,y=TEST),
shape=3, size=1,stroke = 0.25)
xlim(0.4, 1.0)
ylim(0.4, 1.0)
theme(legend.position="top")
xlab("LAST") ylab("TEST")
guides(fill = guide_legend(ncol=1, title=""))
p4b = p4b coord_fixed() guides(fill =guide_legend(ncol=2, title="Interactions", title.position="top",
title.theme = element_text(
size = 15,
face = "bold",
colour = "black",
margin=margin(t = 0, r = 0, b = 0, l = 5, unit = "pt")
)
)
)
p4b
我得到這個數字。問題是我想要的是一個單獨的圖例元素,它代表“ ”形狀,沒有顏色。最后,圖例中應該有 10 個元素,9 個實際彩色圓形(但內部沒有“ ”)和 1 個“ ”。
我看到有些人在使用override.aes該guid_legend部分,但我無法使其作業,而且我現在在這方面已經太久了......

uj5u.com熱心網友回復:
我是從原始帖子開始作業的,其中沒有任何點與 符號相關聯。假設這些是由geom_pointshape = 3 的層繪制的,取自資料框的子集,dta我們可以這樣做:
ggplot(dta, aes(TEST1, TEST, fill = Interaction))
annotation_custom(grob = g3, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
geom_abline(intercept = 0, slope = 1, color="black", size = 1.0)
geom_abline(intercept = c(-0.05, 0.05), slope = 1,
color = "black", linetype = "dotted", size = 0.25, alpha = 0.5)
geom_abline(intercept = c(-0.1, 0.1), slope = 1, color = "black",
linetype = "dashed", size = 0.25, alpha = 0.5)
geom_point(shape = 21, size = 4.5, stroke = 0.25, alpha = 0.9)
geom_point(aes(TEST1, TEST, shape = "Positive"), inherit.aes = FALSE,
size = 1.5, data = dta[sample(nrow(dta), 12),])
scale_shape_manual(values = 3, name = "Special")
xlim(0.4, 1.0)
ylim(0.4, 1.0)
theme(legend.position="top",
legend.key.height= unit(.4, 'cm'),
plot.background = element_blank(),
panel.background = element_rect(fill = "transparent", colour = "gray"),
panel.border = element_rect(fill = "transparent", colour = "black"),
axis.text = element_text(color = "black"),
legend.background = element_blank(),
legend.box.background = element_blank(),
legend.key = element_blank(),
legend.text = element_text(size = 9),
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12),
axis.title.x = element_text(color = "black",size = 13, face = "bold"),
axis.title.y = element_text(color = "black", size=15, face = "bold")
)
xlab("TEST1")
ylab("TEST")
coord_fixed()
guides(fill = guide_legend(ncol = 2,
title = "Interactions",
title.position = "top",
title.theme =
element_text(
size = 15,
face = "bold",
colour = "black",
margin = margin(t = 0, r = 0, b = 0, l = 5,
unit = "pt")
)
),
shape = guide_legend(title = "Special",
title.position = "top",
title.theme = element_text(
size = 15,
face = "bold",
colour = "black",
margin = margin(t = 0, r = 0, b = 0, l = 5,
unit = "pt")
)
))

請注意,我還必須嘗試g3根據有根據的猜測來重建物件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/436071.html
