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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:39:23+00:00 2026-06-16T06:39:23+00:00

When using a ggplot2 theme with a black background, can one control the legend

  • 0

When using a ggplot2 theme with a black background, can one control the legend colour for guides other than the colour guide so that things are not plotted in black? If so, how?

library(ggplot2) # needs to be 0.9.3 for this theme
data(iris)       # included with ggplot2

theme_black<- function (base_size = 16, base_family = ""){
    theme_minimal() %+replace% 
        theme(
              line = element_line(colour = "white", size = 0.5, linetype = 1, 
                        lineend = "butt"), 
              rect = element_rect(fill = "white", 
                        colour = "white", size = 0.5, linetype = 1), 
              text = element_text(family = base_family, 
                        face = "plain", colour = "white", size = base_size,
                        angle = 0, lineheight = 0.9, hjust = 0, vjust = 0),
              plot.background = element_rect(colour = 'black', fill = 'black'),
              plot.title = element_text(size = rel(1.2)),
              panel.border = element_rect(fill = NA, colour = "white"), 
              panel.grid.major = element_line(colour = "grey20", size = 0.2), 
              panel.grid.minor = element_line(colour = "grey5", size = 0.5),
              strip.background = element_rect(fill = "grey30", colour = "grey30")
             )
    }

ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width, shape=Species,
       colour=Petal.Length))+geom_point()+theme_black()+
       scale_colour_gradient(low = "purple", high = "white")

As you can see, the default colour for the shape part of the legend has not been changed, so it is invisible and one cannot tell which species is which:

enter image description here

The only solution I have right now is to change the legend.background colour, but this is a waste of ink and ugly.

  • 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-16T06:39:24+00:00Added an answer on June 16, 2026 at 6:39 am

    One way would be to add two extra geom_points, the logic would be:

    plot white points for the legend, cover them with black points with no legend, then plot your coloured points with no legend,e.g.

    geom_point(colour="white",size=1) + 
    geom_point(colour="black",size=3,show_guide=FALSE) +
    geom_point(show_guide=FALSE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ggplot2 to plot a figure that contains nine facets. Each facet
I have the following graph that I generated using ggplot2 I had finalPlot as
I am trying to produce some example graphics using ggplot2, and one of the
I'm making a straightforward barchart in R using the ggplot2 package. Rather than the
I would like to modify the legend in ggplot2 using the text geom. Example
How can I improve the legend of spatial raster map plot using ggplot when
I am using ggplot2 to plot simple line charts of time series data. One
I would like to reproduce the plot immediately below by using ggplot2. I can
I'm using ggplot2 to make some bullseye charts in R. They look delightful, and
I'm plotting a group of curves, using facet in ggplot2. I'd like to have

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.