1

What I would like to do is to draw a barplot, then click on two colors in order to swap them. For what I read it seems Shiny would do the job. However, is there a way to identify the color at some given coordinates in an R plot without using Shiny? Something as follows:

# I start with this colour set
cols <- 0:9

plot(NA, xlim = c(1,10), ylim = c(1,10)); rect(1:9,1:9,2:10,2:10, col = cols)

# identify the two sets of coordinates to swap colour-wise
coords <- locator(2)

# get the colours with the non-existent colour_at() function
col1 <- colour_at(coords$x)
col2 <- colour_at(coords$y)

# swap colours in the colour set and finally plot again
col1.pos <- which(x == col1); col2.pos <- which(x == col2)

cols <- replace(x, c(col1pos, col2pos), x[c(col2pos, col1pos)])

plot(NA, xlim = c(1,10), ylim = c(1,10)); rect(1:9,1:9,2:10,2:10, col = cols)
Xarylem
  • 398
  • 3
  • 12
  • Your question is precise, but in order for us to understand and solve it, it is necessary that you provide some sample data. There are several ways to provide data, probably adding the output of `dput()` or `dput(head())` to your question is sufficient. Avoid adding code or alphanumeric output as images. Consider how to make a good example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and see how you can change your question accordingly. – heck1 Aug 28 '19 at 07:55

0 Answers0