[R] help with line graphs - rather lengthy to explain need
David L Carlson
dc@rl@on @ending from t@mu@edu
Fri Nov 30 02:37:49 CET 2018
I'm not sure we have enough details to answer your question, but you may need to think about organizing your spreadsheet differently. Perhaps one sheet that has just the data and a second sheet that has the sample number and the location. Import those separately into R.
Your data are in wide format so matplot() would work for what you want to do, but ggplot may easier if you organize them in long format - one long column of readings, one column of sample numbers (repeated for each of the 2048 measurements from a single sample (and the same for the location column).
If this doesn't put you on the right track, give us a .csv file of a subset of the data (e.g. 10 columns and 20 rows) to play with. You can just copy/paste it into your message. If you save it as an attachment, rename the extension to .txt so the list processor does not strip it out.
David L. Carlson
Department of Anthropology
Texas A&M University
-----Original Message-----
From: R-help [mailto:r-help-bounces using r-project.org] On Behalf Of Robert D. Bowers M.A.
Sent: Thursday, November 29, 2018 3:24 PM
To: r-help using r-project.org
Subject: [R] help with line graphs - rather lengthy to explain need
I am trying to figure out the best way to organize and plot data
generated by a Excel spreadsheet (one driving a sample turntable and
collecting optical spectra).
The output of the equipment and software is an excel spreadsheet with
sample numbers in the first row, and in the first column there is the
wavelength in nm. 2048 individual measurements (per wavelength) - 2048
rows plus the sample number row, and at present I've tested 250 samples,
with a LOT more to follow.
After I get the spreadsheet, I add a row (just below the sample numbers)
containing site locations. I've collected 50 samples per site (each
assigned a different number), so far 5 sites. The spreadsheet ends up
with 2050 rows, 250 columns.
What I want to do is generate a line graph of the data (which could be
separated out into sections of the optical spectrum), with line colors
assigned by the site name. Once that's done, the graphs make sense
(right now the only way I can do that is using the spreadsheet software,
and assigning each line the color manually - a very tiresome and
time-consuming process).
So far, I've tried everything I can to get a graph out using R, without
luck. I'm rusty with R and programming... I've used Rcmdr (tried
transposing data, various settings and so on) and 'played' with ggplot -
no success. I'm using Rcmdr to make it easier to work out the bugs,
then will write a short program to process data.
What I'd like to know is (1) what would be the best way to organize the
data - sample numbers (cases) in the first row, or in the first column
with the next row or column being the site name, (2) how would I get
ggplot to plot the line graph showing all of the samples (number listing
not important) and all (or a selection) of the different wavelengths,
while assigning line color based on site name. Once that's done, I can
show the within-group vs between-group variation compared to wavelength.
To give an idea of what the data look like:
(name = Longwave)
Sample 34900 34901 34902 34903 34904 (and so on)
Site Tp Tc Cr Ws Gs
200(nm) 300.5 783.9 101.3 623.8 1385.7
201....
You get the idea. (maximum measurement value is 4098, the instrument
takes multiple scans and averages them).
If I can figure this out, it will speed up my work - which I need to do
so I can get a grant proposal off on time.
Thank you,
Bob
Doctoral Candidate, Applied Anthropology
University of South Florida
______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
More information about the R-help
mailing list