简体   繁体   English

向R中的现有图添加点

[英]Adding points to existing plot in R

I have found multiple posts about this issue but none of them are solving my issue. 我找到了多个有关此问题的帖子,但没有一个可以解决我的问题。 I have an existing plot made in R where I want to highlight points of interest. 我有一个在R中制作的现有图,我想突出显示兴趣点。 I have a dataframe with the base graph and then a column with points of interest (y values). 我有一个带有基础图的数据框,然后是一个带有兴趣点(y值)的列。

what I have done is below: 我所做的如下:

print(points(x=which(df$base %in% df$interest), y=df$interest, pch=19))

So the column 'base' is the base graph and the column 'interest' are the points of interest. 因此,“基础”列是基础图形,而“兴趣”列是兴趣点。 I am searcing for which X's in the base column correlate to the y points of interest and it should plot them. 我正在寻找基列中的X与感兴趣的y点相关的位置,并应绘制它们。 I get no errors, just a simple 'NULL' printed out. 我没有收到任何错误,只是打印了一个简单的“ NULL”。

Any idea what I am doing wrong? 知道我在做什么错吗?

Maybe this trick helps 也许这个技巧有帮助

library(tidyverse)
x <- c(1,2,3,4,5,6)
y <- c(2,4,6,8,10,12)
z <- c(0,0,1,0,0,1)
df <- data.frame(x,y,z)

ggplot(df,aes(x,y))+geom_point(aes(color=as.factor(z)))

I define an extra column for the interesting points in z. 我为z中的有趣点定义了一个额外的列。 Instead of color you also may use size. 除了颜色,您还可以使用尺寸。 Peter 彼得

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM