3 回答

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超8個(gè)贊
#Some test datadat <- data.frame(x=runif(10),y=runif(10), grp = rep(LETTERS[1:5],each = 2),stringsAsFactors = TRUE)#Create a custom color scalelibrary(RColorBrewer)myColors <- brewer.pal(5,"Set1")names(myColors) <- levels(dat$grp)colScale <- scale_colour_manual(name = "grp",values = myColors)
#One plot with all the datap <- ggplot(dat,aes(x,y,colour = grp)) + geom_point()p1 <- p + colScale#A second plot with only four of the levelsp2 <- p %+% droplevels(subset(dat[4:10,])) + colScale

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
library(ggplot2)dataset <- data.frame(category = rep(LETTERS[1:5], 100), x = rnorm(500, mean = rep(1:5, 100)), y = rnorm(500, mean = rep(1:5, 100)))dataset$fCategory < - factor(dataset$category)subdata <- subset(dataset, category %in% c("A", "D", "E"))
ggplot(dataset, aes(x = x, y = y, colour = category)) + geom_point()ggplot(subdata, aes(x = x, y = y, colour = category)) + geom_point()
ggplot(dataset, aes(x = x, y = y, colour = fCategory)) + geom_point()ggplot(subdata, aes(x = x, y = y, colour = fCategory)) + geom_point()
- 3 回答
- 0 關(guān)注
- 2175 瀏覽
添加回答
舉報(bào)