我們可以用annotate
:
ggplot(df, aes(x=SeqIdentityMean,
y=SeqIdentityStdDev,
color=PfamA_ID))+
geom_point(alpha=0.05) +
annotate("point",
df$SeqIdentityMean[special.points],
df$SeqIdentityStdDev[special.points])
使用@ jlhoward的示例數據:
## create artificial data set for this example
set.seed(1) # for reproducibility
n <- 1.4e4 # 14,000 points
df <- data.frame(SeqIdentityMean =rnorm(n, mean=rep(-3:3, each=n/7)),
SeqIdentityStdDev=rnorm(n, mean=rep(-3:3, each=n/7)),
PfamA_ID=rep(1:7, each=n/7))
df$PfamA_ID <- factor(df$PfamA_ID)
## you start here
library(ggplot2)
special.points <- sample(1:n, 7)
編輯1: 我們可以添加annotate("text",...)
ggplot(df, aes(x=SeqIdentityMean,
y=SeqIdentityStdDev)) +
geom_point(alpha=0.05) +
annotate("point",
df$SeqIdentityMean[special.points],
df$SeqIdentityStdDev[special.points],
col="red") +
annotate("text",
df$SeqIdentityMean[special.points],
df$SeqIdentityStdDev[special.points],
#text we want to display
label=round(df$SeqIdentityStdDev[special.points],1),
#adjust horizontal position of text
hjust=-0.1)
編輯2:
#subset of special points
df_sp <- df[special.points,]
#plot
ggplot(df, aes(x=SeqIdentityMean,
y=SeqIdentityStdDev)) +
geom_point(alpha=0.05) +
#special points
geom_point(data=df_sp,
aes(SeqIdentityMean,SeqIdentityStdDev,col=PfamA_ID),size=3) +
#custom legend
scale_colour_manual(name = "Special Points",
values = df_sp$PfamA_ID,
labels = df_sp$SeqIdentityMean)
如何爲突出顯示的點着色,以黑色(與顯示的內容相反)爲顏色,並添加文本 - 在另一列輸入中,僅將特殊點添加到圖例中?謝謝! – AksR
@AksR請參閱編輯。 – zx8754
哎呀,我之前的請求並不清楚。讓我澄清一下。我怎樣才能讓每個不同的標註顏色,然後外面的圖表有顏色和相應的文字(來自輸入數據列#1,但只是special.points)的圖例。所以我不希望它們全都是紅色的,並且不希望它們全部是紅色的,並且不希望它們全部是紅色的,並且不希望它們全部是紅色的,並且不希望它們全部是紅色的,並且不希望它們全部是紅色的,並且不希望它們全部是紅色的,並對不起,是一個痛苦,但新的R,和全新ggplot :) – AksR