Dear R Users,
I have 12 data frames, each of 12 rows and 2 columns.
e.g. FeketeJAN
MEAN SUM_
AMAZON 144.4997874 68348.4
NILE 5.4701955 1394.9
CONGO 71.3670036 21196.0
MISSISSIPPI 18.9273250 6511.0
AMUR 1.8426874 466.2
PARANA 58.3835497 13486.6
YENISEI 1.4668313 592.6
OB 1.4239179 559.6
LENA 0.9342164 387.7
NIGER 4.7245709 826.8
ZAMBEZI 76.6893794 8665.9
YANGTZE 10.6759257 1729.5
I want to do a line plot of the value of Amazon 'Sum' (in this case, 68348.4) for each of the 12 data frames. I've tried doing this as follows:
plot(FeketeJAN[1,2], FeketeFEB[1,2], FeketeMAR[1,2], *through to December* type="l")
but receive: Error in strsplit(log, NULL) : non-character argument
I've also tried:
plot(FeketeJAN$AMAZON[,2], FeketeFEB$AMAZON[,2], *through to December* type="l")
but receive:
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
What is it that I'm doing wrong?!
Many thanks for any advice,
Steve
_________________________________________________________________
[[elided Hotmail spam]]
Simple plotting errors
13 messages · Steve Murray, Uwe Ligges, Baptiste Auguie +4 more
Steve Murray wrote:
Dear R Users,
I have 12 data frames, each of 12 rows and 2 columns.
e.g. FeketeJAN
MEAN SUM_
AMAZON 144.4997874 68348.4
NILE 5.4701955 1394.9
CONGO 71.3670036 21196.0
MISSISSIPPI 18.9273250 6511.0
AMUR 1.8426874 466.2
PARANA 58.3835497 13486.6
YENISEI 1.4668313 592.6
OB 1.4239179 559.6
LENA 0.9342164 387.7
NIGER 4.7245709 826.8
ZAMBEZI 76.6893794 8665.9
YANGTZE 10.6759257 1729.5
I want to do a line plot of the value of Amazon 'Sum' (in this case, 68348.4) for each of the 12 data frames. I've tried doing this as follows:
plot(FeketeJAN[1,2], FeketeFEB[1,2], FeketeMAR[1,2], *through to December* type="l")
but receive: Error in strsplit(log, NULL) : non-character argument
I've also tried:
plot(FeketeJAN$AMAZON[,2], FeketeFEB$AMAZON[,2], *through to December* type="l")
but receive:
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
What is it that I'm doing wrong?!
Well, beside the infelicity of having 12 data.frames to represent one year, your need to make a vector of those values as in: plot(c(FeketeJAN[1,2], FeketeFEB[1,2], FeketeMAR[1,2], *through to December* ), type="l") Uwe Ligges
Many thanks for any advice, Steve
_________________________________________________________________ [[elided Hotmail spam]] ______________________________________________ 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.
I'd suggest you first combine the 12 data.frames into one, using
melt() from the reshape package.
makeDummy <- function(.){ # since you don't provide a reproducible
example
data.frame(x=letters[1:10], y=rnorm(10))
}
listOf12DataFrames <- lapply(1:12, makeDummy)
library(reshape)
dm <- melt(listOf12DataFrames, id="x")
str(dm) # each original data.frame is identified by the integer L1
with(subset(dm, x=="a"),
plot(L1, value, t="l"))
baptiste
On 18 May 2009, at 13:17, Steve Murray wrote:
Dear R Users,
I have 12 data frames, each of 12 rows and 2 columns.
e.g. FeketeJAN
MEAN SUM_
AMAZON 144.4997874 68348.4
NILE 5.4701955 1394.9
CONGO 71.3670036 21196.0
MISSISSIPPI 18.9273250 6511.0
AMUR 1.8426874 466.2
PARANA 58.3835497 13486.6
YENISEI 1.4668313 592.6
OB 1.4239179 559.6
LENA 0.9342164 387.7
NIGER 4.7245709 826.8
ZAMBEZI 76.6893794 8665.9
YANGTZE 10.6759257 1729.5
I want to do a line plot of the value of Amazon 'Sum' (in this case,
68348.4) for each of the 12 data frames. I've tried doing this as
follows:
plot(FeketeJAN[1,2], FeketeFEB[1,2], FeketeMAR[1,2], *through to
December* type="l")
but receive: Error in strsplit(log, NULL) : non-character argument
I've also tried:
plot(FeketeJAN$AMAZON[,2], FeketeFEB$AMAZON[,2], *through to
December* type="l")
but receive:
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
What is it that I'm doing wrong?!
Many thanks for any advice,
Steve
_________________________________________________________________ [[elided Hotmail spam]] ______________________________________________ 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.
_____________________________ Baptiste Augui? School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag
you mean you want to plot "SUM" against month? (assuming these12 data frames are 12 months). you could first bind them all together using data.frame(), see ?data.frame which would make it much easier. you need to create a variable for months then plot it against your variable. If you dont want to make it easier with a data frame then you would have a long piece of code as follows (assuming I have understood you correctly) plot(seq(1:12),c(FeketeJAN$(SUM_)[row.names(FeketeJAN)=="AMAZON"],FeketeFEB$(SUM_)[row.names(FeketeFEB)=="AMAZON"]....etc)) Cheers, Si. ----- Original Message ----- From: "Steve Murray" <smurray444 at hotmail.com> To: <r-help at r-project.org> Sent: Monday, May 18, 2009 12:17 PM Subject: [R] Simple plotting errors
Dear R Users,
I have 12 data frames, each of 12 rows and 2 columns.
e.g. FeketeJAN
MEAN SUM_
AMAZON 144.4997874 68348.4
NILE 5.4701955 1394.9
CONGO 71.3670036 21196.0
MISSISSIPPI 18.9273250 6511.0
AMUR 1.8426874 466.2
PARANA 58.3835497 13486.6
YENISEI 1.4668313 592.6
OB 1.4239179 559.6
LENA 0.9342164 387.7
NIGER 4.7245709 826.8
ZAMBEZI 76.6893794 8665.9
YANGTZE 10.6759257 1729.5
I want to do a line plot of the value of Amazon 'Sum' (in this case,
68348.4) for each of the 12 data frames. I've tried doing this as follows:
plot(FeketeJAN[1,2], FeketeFEB[1,2], FeketeMAR[1,2], *through to December*
type="l")
but receive: Error in strsplit(log, NULL) : non-character argument
I've also tried:
plot(FeketeJAN$AMAZON[,2], FeketeFEB$AMAZON[,2], *through to December*
type="l")
but receive:
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
What is it that I'm doing wrong?!
Many thanks for any advice,
Steve
_________________________________________________________________ [[elided Hotmail spam]] ______________________________________________ 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.
you mean you want to plot "SUM" against month? (assuming these12 data frames are 12 months). you could first bind them all together using data.frame(), see ?data.frame which would make it much easier. you need to create a variable for months then plot it against your variable. If you dont want to make it easier with a data frame then you would have a long piece of code as follows (assuming I have understood you correctly) plot(seq(1:12),c(FeketeJAN$(SUM_)[row.names(FeketeJAN)=="AMAZON"],FeketeFEB$(SUM_)[row.names(FeketeFEB)=="AMAZON"]....etc)) Cheers, Si. ----- Original Message ----- From: "Steve Murray" <smurray444 at hotmail.com> To: <r-help at r-project.org> Sent: Monday, May 18, 2009 12:17 PM Subject: [R] Simple plotting errors
Dear R Users,
I have 12 data frames, each of 12 rows and 2 columns.
e.g. FeketeJAN
MEAN SUM_
AMAZON 144.4997874 68348.4
NILE 5.4701955 1394.9
CONGO 71.3670036 21196.0
MISSISSIPPI 18.9273250 6511.0
AMUR 1.8426874 466.2
PARANA 58.3835497 13486.6
YENISEI 1.4668313 592.6
OB 1.4239179 559.6
LENA 0.9342164 387.7
NIGER 4.7245709 826.8
ZAMBEZI 76.6893794 8665.9
YANGTZE 10.6759257 1729.5
I want to do a line plot of the value of Amazon 'Sum' (in this case,
68348.4) for each of the 12 data frames. I've tried doing this as follows:
plot(FeketeJAN[1,2], FeketeFEB[1,2], FeketeMAR[1,2], *through to December*
type="l")
but receive: Error in strsplit(log, NULL) : non-character argument
I've also tried:
plot(FeketeJAN$AMAZON[,2], FeketeFEB$AMAZON[,2], *through to December*
type="l")
but receive:
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
What is it that I'm doing wrong?!
Many thanks for any advice,
Steve
_________________________________________________________________ [[elided Hotmail spam]] ______________________________________________ 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.
you mean you want to plot "SUM" against month? (assuming these12 data frames are 12 months). you could first bind them all together using data.frame(), see ?data.frame which would make it much easier. you need to create a variable for months then plot it against your variable. If you dont want to make it easier with a data frame then you would have a long piece of code as follows (assuming I have understood you correctly) plot(seq(1:12),c(FeketeJAN$(SUM_)[row.names(FeketeJAN)=="AMAZON"],FeketeFEB$(SUM_)[row.names(FeketeFEB)=="AMAZON"]....etc)) Cheers, Si. ----- Original Message ----- From: "Steve Murray" <smurray444 at hotmail.com> To: <r-help at r-project.org> Sent: Monday, May 18, 2009 12:17 PM Subject: [R] Simple plotting errors
Dear R Users,
I have 12 data frames, each of 12 rows and 2 columns.
e.g. FeketeJAN
MEAN SUM_
AMAZON 144.4997874 68348.4
NILE 5.4701955 1394.9
CONGO 71.3670036 21196.0
MISSISSIPPI 18.9273250 6511.0
AMUR 1.8426874 466.2
PARANA 58.3835497 13486.6
YENISEI 1.4668313 592.6
OB 1.4239179 559.6
LENA 0.9342164 387.7
NIGER 4.7245709 826.8
ZAMBEZI 76.6893794 8665.9
YANGTZE 10.6759257 1729.5
I want to do a line plot of the value of Amazon 'Sum' (in this case,
68348.4) for each of the 12 data frames. I've tried doing this as follows:
plot(FeketeJAN[1,2], FeketeFEB[1,2], FeketeMAR[1,2], *through to December*
type="l")
but receive: Error in strsplit(log, NULL) : non-character argument
I've also tried:
plot(FeketeJAN$AMAZON[,2], FeketeFEB$AMAZON[,2], *through to December*
type="l")
but receive:
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
What is it that I'm doing wrong?!
Many thanks for any advice,
Steve
_________________________________________________________________ [[elided Hotmail spam]] ______________________________________________ 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090518/a9ec5fb5/attachment-0001.pl>
On Mon, 18 May 2009 11:17:50 +0000 Steve Murray
<smurray444 at hotmail.com> wrote:
SM> plot(FeketeJAN[1,2], FeketeFEB[1,2], FeketeMAR[1,2], *through to SM> December* type="l") SM> What is it that I'm doing wrong?! try plot( c(FeketeJAN[1,2], FeketeFEB[1,2], ...)),type="l") however it is better to create one big data frame like: Location Mean Sum Month Amazon 144 ... JAN all you need is cbind. hth Stefan
Thanks for all the useful information; use of 'c(...)' did the trick, although in future I'll try to hold the data in a more user-friendly setup.
I've now got a plot, but have two issues that I can't seem to resolve:
1, The ylab is overlapping the y-axis tick mark values. I've tried using oma and mar to adjust the outer and plot margins respectively, but this doesn't seem to 'detach' the overlapping text.
2. The x-axis currently has tick mark values of 2 to 12. How do change this to single-letter month labels? So far I've tried xlim=c("J","F","M",A","M"...) and names.arg=c("J","F","M"...), but these result in errors.
Any suggestions would be much appreciated.
Thanks again,
Steve
_________________________________________________________________
[[elided Hotmail spam]]
Here is a slight elaboration on Jim's solution:
# create a vector of the names - month.abb is built into R
# This is like: df.names <- c("FetekeJAN", "FetekeFEB", ...)
# but avoids having to write out every name.
df.names <- paste("Feteke", toupper(month.abb), sep = "")
# create a list of the data frames so that df.list[[1]] is FetekeJAN, etc.
df.list <- lapply(df.names, get)
# extract element 1, 2 of each, creating vector amazon.sum
amazon.sum <- sapply(df.list, "[", 1, 2)
# plot it
plot(amazon.sum, xlab = "Month", ylab = "Amazon Sum")
On Mon, May 18, 2009 at 7:17 AM, Steve Murray <smurray444 at hotmail.com> wrote:
Dear R Users, I have 12 data frames, each of 12 rows and 2 columns. e.g. FeketeJAN ? ? ? ? ? ? ? ? ? MEAN ? ?SUM_ AMAZON ? ? ?144.4997874 68348.4 NILE ? ? ? ? ?5.4701955 ?1394.9 CONGO ? ? ? ?71.3670036 21196.0 MISSISSIPPI ?18.9273250 ?6511.0 AMUR ? ? ? ? ?1.8426874 ? 466.2 PARANA ? ? ? 58.3835497 13486.6 YENISEI ? ? ? 1.4668313 ? 592.6 OB ? ? ? ? ? ?1.4239179 ? 559.6 LENA ? ? ? ? ?0.9342164 ? 387.7 NIGER ? ? ? ? 4.7245709 ? 826.8 ZAMBEZI ? ? ?76.6893794 ?8665.9 YANGTZE ? ? ?10.6759257 ?1729.5 I want to do a line plot of the value of Amazon 'Sum' (in this case, 68348.4) for each of the 12 data frames. I've tried doing this as follows: plot(FeketeJAN[1,2], FeketeFEB[1,2], FeketeMAR[1,2], *through to December* type="l") but receive: Error in strsplit(log, NULL) : non-character argument I've also tried: plot(FeketeJAN$AMAZON[,2], FeketeFEB$AMAZON[,2], *through to December* type="l") but receive: Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf What is it that I'm doing wrong?! Many thanks for any advice, Steve
_________________________________________________________________ [[elided Hotmail spam]] ______________________________________________ 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.
read ?par 1.use ylab="" to suppress y labels, then mxtext to manually draw em yourself OR use mgp=... within par() 2.use xlab not xlim to change the x axis labels HTH, Si. ----- Original Message ----- From: "Steve Murray" <smurray444 at hotmail.com> To: <simon.pickett at bto.org>; <r-help at r-project.org>; <ba208 at exeter.ac.uk>; <jholtman at gmail.com> Sent: Monday, May 18, 2009 1:39 PM Subject: RE: [R] Simple plotting errors
Thanks for all the useful information; use of 'c(...)' did the trick,
although in future I'll try to hold the data in a more user-friendly
setup.
I've now got a plot, but have two issues that I can't seem to resolve:
1, The ylab is overlapping the y-axis tick mark values. I've tried using
oma and mar to adjust the outer and plot margins respectively, but this
doesn't seem to 'detach' the overlapping text.
2. The x-axis currently has tick mark values of 2 to 12. How do change
this to single-letter month labels? So far I've tried
xlim=c("J","F","M",A","M"...) and names.arg=c("J","F","M"...), but these
result in errors.
Any suggestions would be much appreciated.
Thanks again,
Steve
_________________________________________________________________ View your Twitter and Flickr updates from one place ? Learn more! http://clk.atdmt.com/UKM/go/137984870/direct/01/
Try this (and make sure to follow the last line to every message on r-help which asks for reproducible code in questions): plot(amazon.sum, xlab = "Month", ylab = "Amazon Sum", xaxt = "n") axis(1, at = 1:12, substr(month.abb, 1, 1))
On Mon, May 18, 2009 at 8:39 AM, Steve Murray <smurray444 at hotmail.com> wrote:
Thanks for all the useful information; use of 'c(...)' did the trick, although in future I'll try to hold the data in a more user-friendly setup.
I've now got a plot, but have two issues that I can't seem to resolve:
1, The ylab is overlapping the y-axis tick mark values. I've tried using oma and mar to adjust the outer and plot margins respectively, but this doesn't seem to 'detach' the overlapping text.
2. The x-axis currently has tick mark values of 2 to 12. How do change this to single-letter month labels? So far I've tried xlim=c("J","F","M",A","M"...) and names.arg=c("J","F","M"...), but these result in errors.
Any suggestions would be much appreciated.
Thanks again,
Steve
_________________________________________________________________ [[elided Hotmail spam]] ______________________________________________ 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.
Many thanks once more for helping me to solve this. Gabor - I wasn't even aware of month.abb, so thanks for bringing this useful trick to my attention! Steve _________________________________________________________________ [[elided Hotmail spam]]