Из приведенных выше комментариев я мог бы решить это следующим образом.
library(ggplot2)
library(plotly)
ID <- c("Group 1", "Group 1", "Group 1", "Group 2", "Group 2", "Group 2", "Group 3", "Group 3", "Group 3", "Group 1", "Group 1", "Group 1")
area <- c("Area 1", "Area 1", "Area 1","Area 2", "Area 2", "Area 2", "Area 3", "Area 3", "Area 3", "Area 4", "Area 4", "Area 4")
colours <- c("Purple", "Purple", "Purple", "Green", "Green", "Green", "yellow", "yellow", "yellow", "Purple", "Purple", "Purple")
x <- c(1.0, 10.25, 50.0, 2.0, 5.0, 30.0, 5.0, 9.0, 10.0, 11.0, 23.0, 40.0)
y <- c(1.0, 3.0, 5.0, 20.0, 10.0, 23.0, 25.0, 19.1, 5.0, 15.0, 8.0, 4.0)
df <- data.frame(ID, area, colours, x, y, stringsAsFactors = FALSE )
###Get colours
colours_poly <- setNames(df$colours, df$ID)
colours_poly
p <- ggplot(df, aes(x=x, y=y)) + geom_polygon(aes(fill=factor(ID), group=area)) +
scale_x_continuous(limits = c(0,50)) +
scale_y_continuous(limits = c(0,30)) +
scale_fill_manual(values = colours_poly)
p <- ggplotly(p)
p
Спасибо большое!