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

  • SEARCH
  • Home
  • 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 7698513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:15:36+00:00 2026-05-31T22:15:36+00:00

Does anyone know any bugs/tricks when using scale_colour_manual to set colors to predefined settings

  • 0

Does anyone know any bugs/tricks when using scale_colour_manual to set colors to predefined settings based on HEX color codes contained in your data frame?

I have been trying to to use the following code to pull predefined color codes from my data frame.

p <- ggplot(df, aes(x, y, colour=company)) 
p <- p + geom_point()
p <- p + scale_colour_manual(breaks=df$company, values = df$col)
p

However, for some reason when the plot is rendered the colors that are in the data (i.e. values=df$col) are not ploted.

Any assistance or guidance would be greatly appreciated. Below is my ggplot structure/data:

structure(list(data = structure(list(x = c(119, 34, 34, 46, 86, 
70, 61, 71, 84, 30, 84, 85, 3, 16, 5, 167, 72, 85, 5, 44, 85, 
63, 15, 86, 148, 83, 105, 11, 11, 98, 169, 14, 11, 28, 98, 52, 
52, 52, 90, 11, 176, 94, 94, 52, 9, 176, 148, 9, 105, 121, 98, 
2, 28, 9, 148, 43, 148, 170, 146, 40, 61, 40, 98, 9, 5, 3, 45, 
46, 6, 128, 123, 39, 45, 2, 19), y = c(1195.26050420168, 4005.55882352941, 
4102.94117647059, 3670.23913043478, 7705.47674418605, 7373.34285714286, 
4745.40983606557, 5158.43661971831, 7686.20238095238, 7301.43333333333, 
7309.02380952381, 7336.03529411765, 3475.33333333333, 5467.4375, 
5117, 3861.70658682635, 8940.34722222222, 7317.41176470588, 4182.8, 
6301.90909090909, 7272.83529411765, 4670.47619047619, 6489.53333333333, 
7452.24418604651, 7762.66891891892, 7768.5421686747, 5560.00504761905, 
9360.71454545455, 10984.6854545455, 6677.94989795918, 5029.19917159763, 
17012.2242857143, 8613.21818181818, 5632.53571428571, 7572.70642857143, 
12890, 8876.30557692308, 12993.5084615385, 364.15, 10914, 13005.2405113636, 
11607.0582978723, 2946.36404255319, 14684.7426923077, 1783.90444444444, 
11400.6083522727, 4940.83817567568, 1609.11111111111, 7636.22476190476, 
318.785123966942, 8798.37673469388, 459.3, 8735.70928571429, 
1616.36222222222, 6279.4397972973, 1564.2711627907, 5410.90743243243, 
2569.18029411765, 6825.9702739726, 22469.3135, 6288.34426229508, 
22726.2695, 11580.1029591837, 1733.73333333333, 2528.8, 1161.66666666667, 
4126.06666666667, 4024.13043478261, 3336.5, 2928.9375, 2675.44715447154, 
4249.79487179487, 7005.95555555556, 1601, 3982.26315789474), 
    company = c("chief", "chief", "chief", "chief", "CHK", "CHK", 
    "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", 
    "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", 
    "CHK", "CHK", "COG", "COG", "COG", "COG", "COG", "COG", "COG", 
    "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", 
    "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", 
    "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", 
    "COG", "COG", "COG", "COG", "CRZO", "CRZO", "CRZO", "CRZO", 
    "CRZO", "Other", "Other", "WPX", "WPX", "WPX", "WPX"), col = c("#000000", 
    "#000000", "#000000", "#000000", "red", "red", "red", "red", 
    "red", "red", "red", "red", "red", "red", "red", "red", "red", 
    "red", "red", "red", "red", "red", "red", "red", "red", "red", 
    "blue", "blue", "blue", "blue", "blue", "blue", "blue", "blue", 
    "blue", "blue", "blue", "blue", "blue", "blue", "blue", "blue", 
    "blue", "blue", "blue", "blue", "blue", "blue", "blue", "blue", 
    "blue", "blue", "blue", "blue", "blue", "blue", "blue", "blue", 
    "blue", "blue", "blue", "blue", "blue", "blue", "darkgreen", 
    "darkgreen", "darkgreen", "darkgreen", "darkgreen", "#000000", 
    "#000000", "orange", "orange", "orange", "orange")), .Names = c("x", 
"y", "company", "col"), row.names = c(NA, -75L), class = "data.frame"), 
    layers = list(<environment>), scales = <S4 object of class structure("Scales", package = "ggplot2")>, 
    mapping = structure(list(x = quote(x), y = quote(y), colour = quote(company)), .Names = c("x", 
    "y", "colour"), class = "uneval"), options = structure(list(
        labels = structure(list(x = "x", y = "y", colour = "company"), .Names = c("x", 
        "y", "colour"))), .Names = "labels"), coordinates = structure(list(
        limits = structure(list(x = NULL, y = NULL), .Names = c("x", 
        "y")), wise = FALSE), .Names = c("limits", "wise"), class = c("cartesian", 
    "coord")), facet = structure(list(shrink = TRUE), .Names = "shrink", class = c("null", 
    "facet")), plot_env = <environment>), .Names = c("data", 
"layers", "scales", "mapping", "options", "coordinates", "facet", 
"plot_env"), class = "ggplot")
  • 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-05-31T22:15:37+00:00Added an answer on May 31, 2026 at 10:15 pm

    Combining the comments from baptiste and joran, either of these work, depending on what you want.

    df <- structure(list(x = c(119, 34, 34, 46, 86, 
    70, 61, 71, 84, 30, 84, 85, 3, 16, 5, 167, 72, 85, 5, 44, 85, 
    63, 15, 86, 148, 83, 105, 11, 11, 98, 169, 14, 11, 28, 98, 52, 
    52, 52, 90, 11, 176, 94, 94, 52, 9, 176, 148, 9, 105, 121, 98, 
    2, 28, 9, 148, 43, 148, 170, 146, 40, 61, 40, 98, 9, 5, 3, 45, 
    46, 6, 128, 123, 39, 45, 2, 19), y = c(1195.26050420168, 4005.55882352941, 
    4102.94117647059, 3670.23913043478, 7705.47674418605, 7373.34285714286, 
    4745.40983606557, 5158.43661971831, 7686.20238095238, 7301.43333333333, 
    7309.02380952381, 7336.03529411765, 3475.33333333333, 5467.4375, 
    5117, 3861.70658682635, 8940.34722222222, 7317.41176470588, 4182.8, 
    6301.90909090909, 7272.83529411765, 4670.47619047619, 6489.53333333333, 
    7452.24418604651, 7762.66891891892, 7768.5421686747, 5560.00504761905, 
    9360.71454545455, 10984.6854545455, 6677.94989795918, 5029.19917159763, 
    17012.2242857143, 8613.21818181818, 5632.53571428571, 7572.70642857143, 
    12890, 8876.30557692308, 12993.5084615385, 364.15, 10914, 13005.2405113636, 
    11607.0582978723, 2946.36404255319, 14684.7426923077, 1783.90444444444, 
    11400.6083522727, 4940.83817567568, 1609.11111111111, 7636.22476190476, 
    318.785123966942, 8798.37673469388, 459.3, 8735.70928571429, 
    1616.36222222222, 6279.4397972973, 1564.2711627907, 5410.90743243243, 
    2569.18029411765, 6825.9702739726, 22469.3135, 6288.34426229508, 
    22726.2695, 11580.1029591837, 1733.73333333333, 2528.8, 1161.66666666667, 
    4126.06666666667, 4024.13043478261, 3336.5, 2928.9375, 2675.44715447154, 
    4249.79487179487, 7005.95555555556, 1601, 3982.26315789474), 
        company = c("chief", "chief", "chief", "chief", "CHK", "CHK", 
        "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", 
        "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", "CHK", 
        "CHK", "CHK", "COG", "COG", "COG", "COG", "COG", "COG", "COG", 
        "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", 
        "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", 
        "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", "COG", 
        "COG", "COG", "COG", "COG", "CRZO", "CRZO", "CRZO", "CRZO", 
        "CRZO", "Other", "Other", "WPX", "WPX", "WPX", "WPX"), col = c("#000000", 
        "#000000", "#000000", "#000000", "red", "red", "red", "red", 
        "red", "red", "red", "red", "red", "red", "red", "red", "red", 
        "red", "red", "red", "red", "red", "red", "red", "red", "red", 
        "blue", "blue", "blue", "blue", "blue", "blue", "blue", "blue", 
        "blue", "blue", "blue", "blue", "blue", "blue", "blue", "blue", 
        "blue", "blue", "blue", "blue", "blue", "blue", "blue", "blue", 
        "blue", "blue", "blue", "blue", "blue", "blue", "blue", "blue", 
        "blue", "blue", "blue", "blue", "blue", "blue", "darkgreen", 
        "darkgreen", "darkgreen", "darkgreen", "darkgreen", "#000000", 
        "#000000", "orange", "orange", "orange", "orange")), .Names = c("x", 
    "y", "company", "col"), row.names = c(NA, -75L), class = "data.frame")
    

    If you want to color points by the given color, use scale_colour_identity():

    ggplot(df, aes(x, y, colour=col)) +
      geom_point() +
      scale_colour_identity()
    

    enter image description here

    There is no scale, because the color itself is the scale.

    If you want to map certain values of company to certain colors, and those colors just happen to be along in the original data set, then you need to pull that mapping out and use the manual scale.

    colmapping <- unique(df[c("company","col")])
    
    ggplot(df, aes(x, y, colour=company)) +
      geom_point() +
      scale_colour_manual(breaks=colmapping$company, values=colmapping$col)
    

    enter image description here

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

Sidebar

Related Questions

Possible Duplicate: PHP: Script for generating Crossword game? Does anyone know any PHP-based simple
does anyone know any tool for 'code generation' using MVC2? I know that ASP
Does anyone know any good tutorial about using NAnt for native code build process
Does anyone know any knowledge of using this: - (void) startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy I
Does anyone know any good solutions for automated deployment to a remote server using
Does anyone know any c++/opengl sourcecode demos for 2D rigid body physics using runge
Does anyone know any good resources with tasks or problems to get practice in
Does anyone know any site or book that presents problems like python challenge ,
Does anyone know any more details about google's web-crawler (aka GoogleBot)? I was curious
does anyone know any sort of app that lets users visit a page on

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.