Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8026349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:27:40+00:00 2026-06-04T23:27:40+00:00

There is probably a very easy solution to my problem but I couldn’t find

  • 0

There is probably a very easy solution to my problem but I couldn’t find a satisfying answer online.

Using the following command I was able to create the following boxplot graph and overlay it with the individual data points:

ggplot(data = MYdata, aes(x = Age, y = Richness)) + 
  geom_boxplot(aes(group=Age)) + 
  geom_point(aes(color = Age))

There are several things I would like to add/change:

1. Change the line color and/or fill of each boxplot (depending on “Age”) using 6 different colors from left to right:

c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00")

I tried

ggplot(data = MYdata, aes(Age, Richness)) + 
  geom_boxplot(aes(group=Age)) + 
  scale_colour_manual(values = c("#E69F00", "#56B4E9", "#009E73", 
                                 "#F0E442", "#0072B2", "#D55E00")) 

but it results in a "Continuous value supplied to discrete scale" error.

2. Change the color of each data point (depending on “Age”) using 6 different colors from left to right:

c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00")

I tried:

ggplot(data = MYdata, aes(Age, Richness)) + 
  geom_boxplot(aes(group=Age)) + 
  geom_point(aes(color = Age)) + 
  scale_colour_manual(values = c("#E69F00", "#56B4E9", "#009E73", 
                                 "#F0E442", "#0072B2", "#D55E00")) 

but it also results in an error:

Continuous value supplied to discrete scale

3. Change the text in the legend to “0 month”, “1 month”, “3 months”, “6 months”, “9 months”, “12 months”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:27:41+00:00Added an answer on June 4, 2026 at 11:27 pm

    First, providing sample data would help. Since you didn’t, here is some:

    MYdata <- data.frame(Age = rep(c(0,1,3,6,9,12), each=20),
                        Richness = rnorm(120, 10000, 2500))
    

    Parts 1 and 2 stem from the same problem. Age is a continuous variable, but you are trying to use it in a discrete scale (by specifying the color for specific values of age). In general, a scale maps the variable to the visual; for a continuous age, there is a corresponding color for every possible value of age, not just the ones that happen to appear in your data. However, you can simultaneously treat age as a categorical variable (factor) for some of the aesthetics. For the third part of your question, within the scale description, you can define specific labels corresponding to specific breaks in the scale. Putting this all together (and adding something to give you the x axis labelled more like what you have in the example):

    ggplot(data = MYdata, aes(x = Age, y = Richness)) + 
      geom_boxplot(aes(fill=factor(Age))) + 
      geom_point(aes(color = factor(Age))) +
      scale_x_continuous(breaks = c(0, 1, 3, 6, 9, 12)) +
      scale_colour_manual(breaks = c("0", "1", "3", "6", "9", "12"),
                          labels = c("0 month", "1 month", "3 months",
                                     "6 months", "9 months", "12 months"),
                          values = c("#E69F00", "#56B4E9", "#009E73", 
                                     "#F0E442", "#0072B2", "#D55E00")) +
      scale_fill_manual(breaks = c("0", "1", "3", "6", "9", "12"),
                          labels = c("0 month", "1 month", "3 months",
                                     "6 months", "9 months", "12 months"),
                          values = c("#E69F00", "#56B4E9", "#009E73", 
                                     "#F0E442", "#0072B2", "#D55E00"))
    

    enter image description here

    With this color scheme, the points that fall inside the boxplot are not visible (since they are the same color as the boxplot’s fill). Perhaps leaving the boxplot hollow and drawing its lines in the color would be better.

    ggplot(data = MYdata, aes(x = Age, y = Richness)) + 
      geom_boxplot(aes(colour=factor(Age)), fill=NA) + 
      geom_point(aes(color = factor(Age))) +
      scale_x_continuous(breaks = c(0, 1, 3, 6, 9, 12)) +
      scale_colour_manual(breaks = c("0", "1", "3", "6", "9", "12"),
                          labels = c("0 month", "1 month", "3 months",
                                     "6 months", "9 months", "12 months"),
                          values = c("#E69F00", "#56B4E9", "#009E73", 
                                     "#F0E442", "#0072B2", "#D55E00"))
    

    enter image description here

    Finally, consider if you really need to color each age differently, since they are well defined by the x-axis already.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is probably a very easy solution for this problem. I could easily do
I've got a problem that probably has a very easy solution, but I can't
This problem is probably very easy to solve but somehow I cannot find a
The solution is probably very simple, but I couldn't just find it .. !
Ok so this i probably very easy but i can't seem to figure it
This is probably very easy, but it's Monday morning. I have two tables: Table1:
This is probably very easy, but I'm having a hard time figuring it out.
I'm very sure this problem has been solved, but I can't find any information
I'm using .Net 2.0 and this is driving me crazy but there's probably some
I'm afraid this is probably a very embarrassingly easy question - but my mind

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.