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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:11:17+00:00 2026-06-05T10:11:17+00:00

The following code: library(ggplot2) theData <- data.frame(category <- sample(LETTERS[1:3], 1000, replace = T), value

  • 0

The following code:

library(ggplot2)
theData <- data.frame(category <- sample(LETTERS[1:3], 1000, replace = T),
                  value <- rnorm(1000))
thePlot <- ggplot(theData,
              aes(x = category, y = value))
thePlot <- thePlot + geom_violin(fill = "BLACK")
thePlot <- thePlot + coord_flip()
print(thePlot)

will produce this plot:

violin plot example

But I would like to achieve an effect whereby the alpha value of the fill (and colour, ideally) of each violin density decreases in less-dense areas. That is, the violin shape fades into the background where the height of the curve is small, but is dark and opaque where the curve is tall. Something like this type of effect:

alpha fade example

Unfortunately, those coefficient plots are produced by use of a pretty ugly hack, and given the flexibility of the new geom_violin, I am wondering if there is a straightforward way to implement this alpha fade in the use of geom_violin.

Thanks for any insight you can offer!

  • 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-05T10:11:19+00:00Added an answer on June 5, 2026 at 10:11 am

    Inspired at @wch’s answer, I decided to take another crack at this. This was as close as I got:

    ggplot(theData, aes(x = category, y = value)) +
        stat_ydensity(geom="segment", aes(xend=..x..+..scaled../2, 
            yend=..y.., alpha=..scaled..), size=2, trim=FALSE) +
        stat_ydensity(geom="segment", aes(xend=..x..-..scaled../2, 
            yend=..y.., alpha=..scaled..), size=2, trim=FALSE) +
        scale_alpha_continuous(range= c(0, 1)) +
        coord_flip() + theme_bw()
    

    enter image description here

    In earlier versions of ggplot2, the plot showed “bands”, but this problem has now apparently been fixed.

    enter image description here

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

Sidebar

Related Questions

I produced multiple plots using the following code: set.seed(12345) a <- data.frame(Glabel=LETTERS[1:7], A=rnorm(7, mean
I have written the following code: library(ggplot2) data <- structure(list(x = c(1L, 6L, 3L,
I compiled the following code as a shared library using g++ -shared ... :
Given the following code (copied from the attoparsec library) what does the inline pragma
In physics library written in C# I have the following code: (in ContactManager.cs) public
I am using Codeigniter message library. In my controller I have the following code
Following code iterates through many data-rows, calcs some score per row and then sorts
Following code is from a sample of playframework-2.0: /** * Display the dashboard. */
The following code is an example from the NCURSES menu library. I'm not sure
The following code was grabbed from MSDN: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.aspx [MetadataType(typeof(ProductMetadata))] public partial class Product {

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.