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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:40:16+00:00 2026-06-18T02:40:16+00:00

I have the following data created on the fly: > df <- data.frame( cbind(rnorm(200),rnorm(200,

  • 0

I have the following data created on the fly:

 > df <- data.frame( cbind(rnorm(200),rnorm(200, mean=.8),rnorm(200, mean=.9),rnorm(200, mean=1),rnorm(200, mean=.2),rnorm(200, mean=.3)),rnorm(200, mean=4),rnorm(200, mean=.5))
 > colnames(df) <- c("w.cancer","w.normal","x.cancer","x.normal","y.cancer","y.normal","z.cancer","z.normal")
 > df_log<-log2(df) # ignore the warning with NA
 > head(df_log)

What I want to do is to create multiple plots in one panel like the sketch below using ‘facet’.
How can I go about it?

enter image description here

  • 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-18T02:40:18+00:00Added an answer on June 18, 2026 at 2:40 am

    You’ll have to prepare your data first. I’ve illustrated this on your data.frame df as it is a proper normal distribution.

    require(ggplot2)
    require(reshape2)
    df$id <- 1:nrow(df)
    
    df.m <- melt(df, "id")
    df.m$grp1 <- factor(gsub("\\..*$", "", df.m$variable))
    df.m$grp2 <- factor(gsub(".*\\.", "", df.m$variable))
    
    p <- ggplot(data = df.m, aes(x=value)) + geom_density(aes(fill=grp2), alpha = 0.4)
    p <- p + facet_wrap( ~ grp1)
    p + scale_fill_brewer(palette = "Set1")
    

    ggplot2_facet_example

    Doing the same by replacing df with df_log you’d get something like this:

    require(ggplot2)
    require(reshape2)
    df_log$id <- 1:nrow(df_log)
    
    df.m <- melt(df_log, "id")
    df.m$grp1 <- factor(gsub("\\..*$", "", df.m$variable))
    df.m$grp2 <- factor(gsub(".*\\.", "", df.m$variable))
    
    p <- ggplot(data = df.m, aes(x=value)) + geom_density(aes(fill=grp2), alpha = 0.5)
    p <- p + facet_wrap( ~ grp1)
    p
    

    ggplog2_facet_log

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

Sidebar

Related Questions

Using python I have created following data frame which contains similarity values: cosinFcolor cosinEdge
I have the following set of data: ID | CREATED | USER -------------------------- 1
I have created following structure 'data' in C typedef struct data { double *dattr;
I have the following data frame in R LOCATION COLOR STATE 1 A green
I have following entity framework code first code. The tables are created and data
I have the following data structure (which was actually created by counting the occurences
I have the following table: CREATE TABLE [dbo].[Data] ( [Id] UNIQUEIDENTIFIER NOT NULL, [Data]
If I have a requirement to create a data structure that has the following
I have the following tables: 1) TBL (ID, Data, LastUpdated, DateCreated) 2) TBL_LOG(Log_ID, LogCreateDate,
I have following data frames > head(elo) date elo 1 1921-12-18 1597 2 1922-05-14

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.