GGplot2更改图例项目

时间:2017-07-25 09:13:36

标签: r ggplot2 legend

由于时间过程,我有更多的传奇项目,但我只想展示两个标签:健康和患者。

ExchangeService service = new ExchangeService("ExchangeVersion");
service.Credentials = new WebCredentials("Username", "Password", "Domain");
service.AutodiscoverUrl("Email", RedirectionUrlValidationCallback);

enter image description here

1 个答案:

答案 0 :(得分:3)

您需要在dataTab中为X和填充美学创建两个不同的变量:

healthy <- rnorm(100, mean = 0, sd = 1)
patientTimeA <- rnorm(100, mean = 1, sd = 1)
patientTimeB <- rnorm(100, mean = 3, sd = 1)
patientTimeC <- rnorm(100, mean = 4, sd = 1)
groupArray <- c(rep("H", 100),rep("P", 300))
timeArray <- c(rep(0, 100), rep(10, 100), rep(20, 100), rep(30, 100))
dataTab <- data.frame(group = groupArray, time = timeArray, 
                      value = c(healthy, patientTimeA, patientTimeB, patientTimeC))
dataTab$group1 <- paste(dataTab$group, dataTab$time, sep = "_")
colVector <- c("red", "blue", "blue", "blue")

p <- ggplot(dataTab, aes(x = group1, y = value, fill = group)) +
  geom_boxplot(alpha = 0.7) +
  scale_fill_manual(values = colVector) 
print(p)

enter image description here