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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:04:56+00:00 2026-06-13T08:04:56+00:00

I would like to plot each column of a data.frame using a histogram on

  • 0

I would like to plot each column of a data.frame using a histogram on one page. Here is an example using the sample “diamonds” data set which comes with R:

p = list()
for (i in 1:ncol(diamonds)) p[[i]] <- qplot(diamonds[,i], xlab=names(diamonds)[[i]])
do.call(grid.arrange, p)

enter image description here

This does plot all the columns, but the data looks the same in each one. So, something is clearly wrong.

Is this the right approach for this task? I’m sure I have some silly syntax somewhere that is assigning the same column data set to each element in the list, but I’m not sure what it is.

Thank you

  • 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-13T08:04:57+00:00Added an answer on June 13, 2026 at 8:04 am

    Here you go:

    library(reshape2)
    library(ggplot2)
    d <- melt(diamonds[,-c(2:4)])
    ggplot(d,aes(x = value)) + 
        facet_wrap(~variable,scales = "free_x") + 
        geom_histogram()
    

    enter image description here

    melting allows us to use the resulting grouping variables (called variable) to split the data into groups and plot a histogram for each one. Note the use of scales = "free_x" because each of the variables has a markedly different range and scale.

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

Sidebar

Related Questions

I'm using Flot and would like to associate text with each individual plot point
Suppose one would like to plot 2 sets of data with unequal number of
I would like to plot an INDIVIDUAL box plot for each unrelated column in
I have a large real 1-d data set called r. I would like plot:
Using R, I would like to plot a linear relationship between two variables, but
I would like to produce a spider (aka radar/star) plot using Gnuplot where different
I have some US demographic and firmographic data. I would like to plot zipcode
The data frame has n columns and I would like to get n plots,
I would like to plot points in two dimensional fashion (each have an x
I have a dataframe in R like this: dat = data.frame(Sample = c(1,1,2,2,3), Start

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.