I have a grid of equi-spaced points (13*8). I want to plot some specific points in that grid in a different color. The coordinates for those specific points are stored in a different matrix. Can someone please help me out with this?
Here's the code I am using to generate the grid.
ggplot(data=a,aes(x=X,y=Y))+geom_point()
'a' basically contains the coordinates for the points plotted in the grid. Those points are supposed to mimic the locations of a bolt on a plate.
Here's the matrix that contains the coordinates for the points to be highlighted
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.