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 8546997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:09:55+00:00 2026-06-11T13:09:55+00:00

Expected Behavior If I create a plot with ggplot2 and use separate, say, shape

  • 0

Expected Behavior

If I create a plot with ggplot2 and use separate, say, shape and fill scales to delineate data, I would expect the legend would delineate between “white” filled points (which look hollow) and “black” filled points (which do not look hollow).

In the example code below, the legend item for Windows should be a white hollow point, and that for Linux should be a black filled in point

Actual Behavior

The legend items under “Operating System” depict two visually identical points for what are clearly different operating systems whose points are clearly drawn with different fills on the graph. In the sample code below, both Windows and Linux appear as indistinguishable black hollow points in the legend, even though they’re properly plotted differently on the plot itself.

Sample Plot

Sample plot with broken fill behavior in the legend

Sample Code

library(ggplot2)

x <- rnorm(n = 30)
y <- rnorm(n = 30)
treatment <- rep(c("red", "green", "blue"), times = 20)
operatingSystem <- rep(c("Windows", "Linux"), times = 30)

dd <- data.frame(x, y, treatment, operatingSystem)

fillScaleValues <- c(
  "Windows" = "white",
  "Linux" = "black"
)

shapeScaleValues <- c(
  "red" = 21,
  "green" = 22,
  "blue" = 23
)

p <- ggplot(
      aes(x = x, 
          y = y,
          shape = factor(treatment),
          fill = factor(operatingSystem)
      ), data = dd
     )

p <- p + geom_point()
p <- p + scale_fill_manual(values = fillScaleValues, name = "Operating System")
p <- p + scale_shape_manual(values = shapeScaleValues, name = "Treatment")

p

Session Info

R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C/en_US.UTF-8/C/C/C/C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_0.9.2.1       reshape2_1.2.1        plyr_1.7.1            ProjectTemplate_0.4-2
[5] testthat_0.7         

loaded via a namespace (and not attached):
 [1] MASS_7.3-21        RColorBrewer_1.0-5 colorspace_1.1-1   dichromat_1.2-4   
 [5] digest_0.5.2       evaluate_0.4.2     grid_2.15.1        gtable_0.1.1      
 [9] labeling_0.1       memoise_0.1        munsell_0.4        proto_0.3-9.2     
[13] scales_0.2.2       stringr_0.6.1      tools_2.15.1      
  • 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-11T13:09:57+00:00Added an answer on June 11, 2026 at 1:09 pm

    You have to override the shape that’s being used in the legend, as seen in this question.

    So using your example code (thanks for the clear, reproducible question, by the way), all you need to do is:

    p + guides(fill = guide_legend(override.aes = list(shape = 21)))
    

    Which gives you what you wanted:

    Proper legend

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

Sidebar

Related Questions

Is it expected behavior that two encodings can map to the same decoding? I'm
I encountered some curious behavior today and was wondering if it is expected or
Most of the code works as expected, but I'm getting some unusual behavior under
This time I get a strange behavior with NSFetchedResultsController. I create a fetchRequest like
I have a vb6 multithreaded app working and i would like to use mutexes
If I create a UITableViewController - drilling down works as expected. If a user
I am trying to use R to create a raster image from a matrix
I'm not really sure why the following console application doesn't produce the expected behavior
In my application, I thought it would be a good idea to create a
I'm have difficulty finding any docs describing Python's expected symlink behavior. I've tried testing

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.