ggplot2:改变`color`的顺序

时间:2017-02-17 17:25:32

标签: r ggplot2

我有一个如下图,我想将彩色线的顺序从蓝色 - >绿色 - >>红色改为r-> g-> b,这样它就像传说的一样订购。我找到了几个教程来改变传说的顺序,但我想在这种情况下保持它的顺序(因为它们是1,2和3)。

Figure

以下是生成数据和图形的代码。

population_num <- 100
population <- tibble(
    gender = as.numeric(rbinom(population_num, 1, 0.5)),
    age=rnorm(population_num, mean=50, sd=20),
    score=rnorm(population_num, mean=80, sd=30),
    setid=sample(c(1,2,3), size=population_num, replace=T)
    )
temp <- population %>%
  group_by(setid) %>%
  do(model1 = tidy(lm(score ~ age, data = .)),
     model2 = tidy(lm(score ~ age + gender, data = .))) %>% 
  gather(model_name, model, -setid) %>%                     
  unnest() %>%                                              
  filter(term == "age")                                     

interval1 <- -qnorm((1-0.9)/2)

ggplot(temp, aes(colour = as.factor(setid))) +
  geom_hline(yintercept = 0, colour = gray(1/2), lty = 2) +
  geom_linerange(aes(x = model_name, ymin = estimate - std.error*interval1,
                     ymax = estimate + std.error*interval1),
                 lwd = 1, position = position_dodge(width = 1/2)) +
 scale_x_discrete(limits=c("model2", "model1"), labels=c("M2", "M1")) +
  coord_flip()

(这个问题曾经在日语Stackoverflow中被问到,但无法得到答案。)

1 个答案:

答案 0 :(得分:1)

您可以将$fileToUpload = mysql_real_escape_string($_POST['file']); if(isset($_POST['btn-upload'])) { if(mysql_query("INSERT INTO rdixon.tbl_users (ProfilePicture) VALUES ('$fileToUpload')WHERE tbl_users.UserID=".$_SESSION['user'])) { echo "<script>alert('Profile picture successfully uploaded')</script>"; header("location: login.php"); } else { echo "<script>alert('Upload error, please try again')</script>"; } } 的{​​{1}}参数更改为否定。这确实会产生警告:

width

但情节很好:

position_dodge