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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:43:16+00:00 2026-06-01T17:43:16+00:00

I recently upgraded to ggplot2 0.9.0 from version 0.8.9, and now I’m getting that

  • 0

I recently upgraded to ggplot2 0.9.0 from version 0.8.9, and now I’m getting that my plot legends only show the factor levels used in the plot (it omits the unused ones). Before it’d include all factor levels in the legend. I’m running Windows 7 and R 2.15.0 (2.14.2 before today).

Is anyone else finding this too? Is there a way I can get the unused factor levels to display in my plot legend?

library(ggplot2)

df <- data.frame(fruit = rep(c("apple", "orange"), times=11), 
                 year = 1990:2011, 
                 qty = rnorm(22, 100, 20))

# This plot only gives "apple" in the legend now.
# Before, I used to get both "apple" and "orange". 
qplot(year, qty, data = subset(df, fruit=="apple"), colour = fruit) 

The qplot() used to give me both "apple" and "orange" in the legend (even though there were only points for "apple"). Now I only get "apple" in the legend.

Reason this came up – I am making many plots of subsets of a data set and I want the legends standardized across plots (normally I’d appreciate the unused levels being automatically dropped and not having to type droplevels(), but this is the one case I want those unused levels). Apologies if this is a question local to my computer only.


Edit: Note that as of R 4.0.0, the above code no longer produces a df$fruit as a factor, which changes the behavior of ggplot in the question and answers below. To reproduce use:

df <- data.frame(
  fruit = factor(rep(c("apple", "orange"), times=11)), 
  year = 1990:2011, 
  qty = rnorm(22, 100, 20)
)
  • 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-01T17:43:17+00:00Added an answer on June 1, 2026 at 5:43 pm

    Yes, you want to add drop = FALSE to your colour scale:

    ggplot(subset(df,fruit == "apple"),aes(x = year,y = qty,colour = fruit)) + 
        geom_point() + 
        scale_colour_discrete(drop = FALSE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently upgraded to Eclipse Ganymede from Europa and now I'm finding that when
I recently upgraded from jQuery 1.2.6 to 1.3.2 Now on the page I'm using
I recently upgraded from 4.0.1 to 4.2.1 and noticed that when I publish to
I recently upgraded XCode to run iOS 4.2 from iOS 3.2. However, now, when
I recently upgraded my tortoise to version 1.7. It's been a while now I
I recently upgraded a number of projects from VS2008 to VS2010. Now I'm having
I recently upgraded my machine from Leopard to Snow Leopard. Also I installed the
I recently upgraded to using ReSharper 5 (currently in beta). I noticed that in
I recently upgraded my app from Spring 2.5.6 to Spring 3.0.0. A few days
I recently upgraded to the latest version of flashbuilder. Imported my the project I

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.