Hello! Thanks for reading this request for assistance. I have a question regarding creating a histogram-like figure from data that are not currently in the correct format for the "hist" command. Specifically, my data have been processed and are in a matrix with columns containing the variables of interest and separate columns containing the number of times this variable was observed (counts). This data frame/matrix is rather large (1600 rows), and there are multiple rows corresponding to the same variable level (e.g., "temperature=8, 5 observations" in one row, then the next: "temperature=8, 9 observations", and so on). In other words, the data are not one long vector R can read and plot as a histogram, nor are they condensed. My goal is to create a figure in which one axis is bins (e.g., temperature values) and the other is number of observations in this bin (e.g., number of organisms seen). My question is: Is there a way R can be told to read my data to create a plot like that I desire? So far I have tried several options, including bar plots with no success. If there is no way to do this with my data as the are currently arrange, is there an efficient way to re-arrange them? Thanks a lot for any assistance or advice! Sincerely, Paul Simonin -- Paul W. Simonin Graduate Research Assistant, MS Program Vermont Cooperative Fish and Wildlife Research Unit The Rubenstein School of Environment and Natural Resources University of Vermont 81 Carrigan Dr. Burlington, VT 05405 Ph:802-656-3153
It would be easier if you were to make a data frame of fake values to illustrate your point, so that we could just copy it into an R session and see if we can't get it to work. So, a stab in the dark would to look at ggplot2 specifically the hist argument in qplot and the facets, the lattice package, or reshape to change the format of your data. If you want me to fool around with it use dput and take a small subset of your data or make up data to be able to be copied into an R session. hope that helps, Stephen On Fri, Apr 17, 2009 at 10:59 AM, Paul Warren Simonin <Paul.Simonin at uvm.edu> wrote:> Hello! > ?Thanks for reading this request for assistance. I have a question regarding > creating a histogram-like figure from data that are not currently in the > correct format for the "hist" command. > ?Specifically, my data have been processed and are in a matrix with columns > containing the variables of interest and separate columns containing the > number of times this variable was observed (counts). This data frame/matrix > is rather large (1600 rows), and there are multiple rows corresponding to > the same variable level (e.g., "temperature=8, 5 observations" in one row, > then the next: "temperature=8, 9 observations", and so on). In other words, > the data are not one long vector R can read and plot as a histogram, nor are > they condensed. My goal is to create a figure in which one axis is bins > (e.g., temperature values) and the other is number of observations in this > bin (e.g., number of organisms seen). > ?My question is: Is there a way R can be told to read my data to create a > plot like that I desire? So far I have tried several options, including bar > plots with no success. > > ?If there is no way to do this with my data as the are currently arrange, is > there an efficient way to re-arrange them? > > Thanks a lot for any assistance or advice! > > Sincerely, > Paul Simonin > > > -- > Paul W. Simonin > Graduate Research Assistant, MS Program > Vermont Cooperative Fish and Wildlife Research Unit > The Rubenstein School of Environment and Natural Resources > University of Vermont > 81 Carrigan Dr. > Burlington, VT 05405 > Ph:802-656-3153 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Stephen Sefick Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
On Fri, Apr 17, 2009 at 9:59 AM, Paul Warren Simonin <Paul.Simonin at uvm.edu> wrote:> Hello! > ?Thanks for reading this request for assistance. I have a question regarding > creating a histogram-like figure from data that are not currently in the > correct format for the "hist" command. > ?Specifically, my data have been processed and are in a matrix with columns > containing the variables of interest and separate columns containing the > number of times this variable was observed (counts). This data frame/matrix > is rather large (1600 rows), and there are multiple rows corresponding to > the same variable level (e.g., "temperature=8, 5 observations" in one row, > then the next: "temperature=8, 9 observations", and so on). In other words, > the data are not one long vector R can read and plot as a histogram, nor are > they condensed. My goal is to create a figure in which one axis is bins > (e.g., temperature values) and the other is number of observations in this > bin (e.g., number of organisms seen). > ?My question is: Is there a way R can be told to read my data to create a > plot like that I desire? So far I have tried several options, including bar > plots with no success. > > ?If there is no way to do this with my data as the are currently arrange, is > there an efficient way to re-arrange them?In fact, this is very easy to do with ggplot2: install.packages("ggplot2") library(ggplot2) qplot(value, weight = numofobservations, data = mydf, geom="histogram") Hadley -- http://had.co.nz/
here is one way:> mydata <- data.frame(observ=sample(1:10,20,TRUE), value=sample(1:6,20,TRUE)) > > mydataobserv value 1 3 6 2 4 2 3 6 4 4 10 1 5 3 2 6 9 3 7 10 1 8 7 3 9 7 6 10 1 3 11 3 3 12 2 4 13 7 3 14 4 2 15 8 5 16 5 5 17 8 5 18 10 1 19 4 5 20 8 3> hist(rep(mydata$value, mydata$observ))On Fri, Apr 17, 2009 at 10:59 AM, Paul Warren Simonin <Paul.Simonin at uvm.edu> wrote:> Hello! > ?Thanks for reading this request for assistance. I have a question regarding > creating a histogram-like figure from data that are not currently in the > correct format for the "hist" command. > ?Specifically, my data have been processed and are in a matrix with columns > containing the variables of interest and separate columns containing the > number of times this variable was observed (counts). This data frame/matrix > is rather large (1600 rows), and there are multiple rows corresponding to > the same variable level (e.g., "temperature=8, 5 observations" in one row, > then the next: "temperature=8, 9 observations", and so on). In other words, > the data are not one long vector R can read and plot as a histogram, nor are > they condensed. My goal is to create a figure in which one axis is bins > (e.g., temperature values) and the other is number of observations in this > bin (e.g., number of organisms seen). > ?My question is: Is there a way R can be told to read my data to create a > plot like that I desire? So far I have tried several options, including bar > plots with no success. > > ?If there is no way to do this with my data as the are currently arrange, is > there an efficient way to re-arrange them? > > Thanks a lot for any assistance or advice! > > Sincerely, > Paul Simonin > > > -- > Paul W. Simonin > Graduate Research Assistant, MS Program > Vermont Cooperative Fish and Wildlife Research Unit > The Rubenstein School of Environment and Natural Resources > University of Vermont > 81 Carrigan Dr. > Burlington, VT 05405 > Ph:802-656-3153 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?