繁体   English   中英

在 R 中以不同颜色绘制某些点

[英]Plotting certain points in different colors in R

我有一个等距点(13 * 8)的网格。 我想以不同的颜色绘制该网格中的一些特定点。 这些特定点的坐标存储在不同的矩阵中。 有人可以帮我解决这个问题吗?

在此处输入图片说明

这是我用来生成网格的代码。

ggplot(data=a,aes(x=X,y=Y))+geom_point()

'a' 基本上包含绘制在网格中的点的坐标。 这些点应该模仿板上螺栓的位置。

这是包含要突出显示的点的坐标的矩阵

    sigbolts
      x.c y.c
 [1,]   4   4
 [2,]   4   5
 [3,]   3   6
 [4,]   4   6
 [5,]   5   6
 [6,]   3   7
 [7,]   4   7
 [8,]   5   7
 [9,]   3   8
[10,]   4   8
[11,]   5   8
[12,]   8   8
[13,]   4   9
[14,]   4  10
[15,]   6  13
library(tidyverse)

a = as_data_frame(expand.grid(1:10,1:10))
colnames(a) = c('x', 'y')
sigbolts = data_frame(x.c = c(1,3,5), y.c = c(2,4,2))
sigbolts$indicator = 1

df = left_join(a, sigbolts, by = c('x' = 'x.c', 'y' = 'y.c')) %>%
    mutate(indicator = as.factor(ifelse(is.na(indicator), 0, 1)))

ggplot(df, aes(x = x, y = y, color = indicator)) +
    geom_point()

暂无
暂无

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

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