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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:44:42+00:00 2026-05-13T20:44:42+00:00

In R it is easy to turn a matrix into a boxplot > myMatrix

  • 0

In R it is easy to turn a matrix into a boxplot

> myMatrix
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]   27   32   31   28   20   28   10   29   15    29
 [2,]   31   33   20   28   21    9   14   21   34    33
 [3,]   27   33   28   23   26   33   19   11   26    30
 [4,]   33   17   10   31   10   32   10   29   31    28
 [5,]   25   10   29   34   32   33   28   32   32    32
 [6,]   32   19   13   32   26   20    9   26   32    33
 [7,]   33   32   18   26   27   28   29   32   24    25
 [8,]   33   34   32   30   27   31   22   32   33    30
 [9,]   32   34   31   22   17   31   11   27   18    23
[10,]   26   10   30   30   27    4    4    4    4     4

> boxplot(as.data.frame(myMatrix))

How do I accomplish the same thing in ggplot?

  • 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-05-13T20:44:43+00:00Added an answer on May 13, 2026 at 8:44 pm

    You could use the melt() function and then geom_boxplot().
    First reproduce the data (thanks to Excel):

    vec <- c(c(27, 32, 31, 28, 20, 28, 10, 29, 15, 29), 
     + c(31, 33, 20, 28, 21,  9, 14, 21, 34, 33), 
     + c(27, 33, 28, 23, 26, 33, 19, 11, 26, 30), 
     + c(33, 17, 10, 31, 10, 32, 10, 29, 31, 28), 
     + c(25, 10, 29, 34, 32, 33, 28, 32, 32, 32), 
     + c(32, 19, 13, 32, 26, 20,  9, 26, 32, 33), 
     + c(33, 32, 18, 26, 27, 28, 29, 32, 24, 25), 
     + c(33, 34, 32, 30, 27, 31, 22, 32, 33, 30), 
     + c(32, 34, 31, 22, 17, 31, 11, 27, 18, 23), 
     + c(26, 10, 30, 30, 27,  4,  4,  4,  4,  4))
    myMatrix <- matrix(data=vec, ncol=10, byrow=TRUE)
    

    Then melt and plot:

    library(reshape)
    library(ggplot2)
    ggplot(data=melt(as.data.frame(myMatrix)), aes(variable, value)) + geom_boxplot()
    

    Also, as Hadley suggested (long ago) in the comments, there is no need to cast the matrix to a data frame:

    ggplot(data=melt(myMatrix), aes(as.factor(X2), value)) + geom_boxplot()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy way to turn a mysql table into a redis equivalent?
<things> <fruit>apple</fruit> <hardware>mouse</hardware> ... </things> Turn it into: {'things':[{'fruit':'apple'}, {'hardware':'mouse'}]} Is there an easy
Some easy points for somebody here, take the following table of data: EventCode ProcessId
I can't find an easy way to turn off word wrap in a JTextPane.
I want to turn C:\abc.bmp into abc.bmp , or even better, if possible, in
Is there an easy way in Drupal 6 to turn off certain navigation items
I am wondering if there is an easy way to turn a string like:
I develop python application which I decided to turn into package to be installed
Curly brace matching was pretty easy to turn on. How can I turn on
In Microsoft Access there was an easy method to turn off screen updates by

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.