Skip to content

qplot with many files (each one curve)

7 messages · Jonas Stein, Ben Bolker, Nicolai Schneider +3 more

#
Hi,

i would like to plot a few hundred .csv files. 
Each file contains one curve with x,y values to plot.

I have been searching for "gnu r read many files qplot" 
and similar words. I found for loops that use assign to generate 
one variable containing a dataframe.

When i uesed the classic "plot' command i could add 
the curves with something like

for... {
data<-read.csv....
points(data$x, data$y, col=myrainbow, type="l")
}

How would you solve it in ggplot?

Kind regards,
#
Jonas Stein <news <at> jonasstein.de> writes:
I would use something along the lines of

L <- lapply(list.files(pattern),read.csv)

  to read the files into a list.

Something like

L2 <- mapply(function(i,x) {
    data.frame(file=i,x) },seq_along(L),L)

to add an index column to each data frame

L3 <- do.call(rbind,L2)

to combine them all into a single data frame

and

ggplot(L3,aes(x=x,y=y,group=file))+geom_line()
#
Hello,

I?m really sorry to bother you with this problem but it took me a whole day searching for a solution.

I want the y axis labels positioned closer to the y axis, by default they are partly outside the window.


Example:

x <- as.zoo(EuStockMarkets)

par(las=1)

plot.zoo(x, type="l", main="", xlab="", yaxt="n", xaxs="i")
title(main="Title", xlab="index")

par(las=0)


Thanks in advance!


Best,
Nico
#
On Sep 10, 2012, at 8:24 AM, Nicolai Schneider wrote:

            
I could be wrong, but I think you need to specify xaxt="n" to suppress the standard axis and then use axis to supply your own choices.
#
Either way, there is a par() parameter to control the axis and label title
position.
Look at the entry for 'mgp' in ?par

-Don
#
Hi Nico,

Far from the most elegant solution, at least it works and will give you plenty of freedom to choose where to place the labels:
Hope it helps,

Jos?



Jos? Iparraguirre
Chief Economist
Age UK

T 020 303 31482
E Jose.Iparraguirre at ageuk.org.uk
Twitter @jose.iparraguirre at ageuk


Tavis House, 1- 6 Tavistock Square
London, WC1H 9NB
www.ageuk.org.uk?| ageukblog.org.uk | @ageukcampaigns 


For evidence and statistics on the older population, visit the Age UK Knowledge Hub http://www.ageuk.org.uk/professional-resources-home/knowledge-hub-evidence-statistics/


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Nicolai Schneider
Sent: 10 September 2012 16:24
To: r-help at stat.math.ethz.ch
Subject: [R] Position of y axis labels in plot graphic

Hello,

I?m really sorry to bother you with this problem but it took me a whole day searching for a solution.

I want the y axis labels positioned closer to the y axis, by default they are partly outside the window.


Example:

x <- as.zoo(EuStockMarkets)

par(las=1)

plot.zoo(x, type="l", main="", xlab="", yaxt="n", xaxs="i")
title(main="Title", xlab="index")

par(las=0)


Thanks in advance!


Best,
Nico
______________________________________________
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.

Age UK and YouthNet are official charities for the Virgin London Marathon 2013

We need you to Run for it. Join the team and help raise vital funds to bring generations together to combat loneliness and isolation.

Go to http://www.runforit.org.uk for more information or contact Helen Parson at helen.parsons at ageuk.org.uk or on 020 303 31369.

Age UK and YouthNet. A lifeline, online.

www.runforit.org.uk



Age UK Improving later life

www.ageuk.org.uk



-------------------------------
Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). 
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer 
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health 
cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and 
regulated by the Financial Services Authority. 
------------------------------

This email and any files transmitted with it are confide...{{dropped:28}}
#
Thanks a lot to everyone who gave my me advice.

Btw, the most elegant solution came from a German R user who "simply" extended the plot.zoo function by the parameter line (ie the distance of the y labels from the y axis).

Here the URL of his posting and the code, unfortunately his comments are written in German only:

http://forum.r-statistik.de/viewtopic.php?f=9&t=2819

Thanks again,
Nico

Am 11.09.2012 um 13:08 schrieb Jose Iparraguirre: