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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:37:40+00:00 2026-06-17T13:37:40+00:00

I am completely new to using ggplot2 but heard of it’s great plotting capabilities.

  • 0

I am completely new to using ggplot2 but heard of it’s great plotting capabilities. I have a list with of different samples and for each sample observations according to three instruments. I would like to turn that into a figure with boxplots. I cannot include a figure but the code to make an example figure is included below. The idea is to have for each instrument a figure with boxplots for each sample.

In addition, next to the plots I would like to make a sort of legend giving a name to each of the sample numbers. I have no idea on how to start doing this with ggplot2.

Any help will be appreciated

The R-code to produce the example image is:

#Make data example
Data<-list();
Data$Sample1<-matrix(rnorm(30),10,3);
    Data$Sample2<-matrix(rnorm(30),10,3);
Data$Sample3<-matrix(rnorm(30),10,3);
    Data$Sample4<-matrix(rnorm(30),10,3);

#Make the plots
par(mfrow=c(3,1)) ;
boxplot(data.frame(Data)[seq(1,12,by=3)],names=c(1:4),xlab="Sample number",ylab="Instrument 1");
boxplot(data.frame(Data)[seq(2,12,by=3)],names=c(1:4),xlab="Sample number",ylab="Instrument 2");
boxplot(data.frame(Data)[seq(3,12,by=3)],names=c(1:4),xlab="Sample number",ylab="Instrument 3");
  • 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-17T13:37:41+00:00Added an answer on June 17, 2026 at 1:37 pm

    First, you’ll want to set your data up differently: as a data.frame rather than a list of matrices. You want one column for sample, one column for instrument, and one column for the observed value. Here’s a fake dataset:

    df <- data.frame(sample = rep(c("One","Two","Three","Four"),each=30), 
                     instrument = rep(rep(c("My Instrument","Your Instrument","Joe's Instrument"),each=10),4),
                     value = rnorm(120))
    
    > head(df)
      sample    instrument       value
    1    One My Instrument  0.08192981
    2    One My Instrument -1.11667766
    3    One My Instrument  0.34117450
    4    One My Instrument -0.42321236
    5    One My Instrument  0.56033804
    6    One My Instrument  0.32326817
    

    To get three plots, we’re going to use faceting. To get boxplots we use geom_boxplot. The code looks like this:

    ggplot(df, aes(x=sample,y=value)) + 
      geom_boxplot() + 
      facet_wrap(~ instrument, ncol=1)
    

    enter image description here

    Rather than including a legend for the sample numbers, if you put the names directly in the sample variable it will print them below the plots. That way people don’t have to reference numbers to names: it’s immediately clear what sample each plot is for. Note that ggplot puts the factors in alphabetical order by default; if you want a different ordering you have to change it manually.

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

Sidebar

Related Questions

Using wxPython (I am completely new to it), I have created a taskbar icon
I am completely new to using string arrays. Consider this example: I have the
I am completely new to chipmunk and I have just been using it for
I'm completely new to databases, and have put something simple together using the helpful
Hello I'm completely new to using Jaspersoft iReport Designer. I want to have a
Possible Duplicate: Using same MySQL Connection in different PHP pages This is completely new
I am a completely new to JPA+Hibernate+Spring (but I have a fairly much experience
Completely new to using simple XML library in PHP, and have been using the
Not completely new to PHP itself, but new to using OOP w/ PHP. Object
I am completely new to java and I am using Solr search server. It

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.