ylim in barplot()

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ylim in barplot()

EYSSAUTIER Stéphanie
Dear useRs,

I'm having troubles with using ylim in barplot(): even though I reduce
the y-scale using ylim, the bars still extend down to 0into the x-labels.
The sample data is below, and here is the code.

#This works fine but I would like to plot only from 50 to 70:
barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
"purple"), legend=TRUE, las=2, axis.lty=1)

#This is the ylim version with the bar problem:
barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
"purple"), ylim=c(50,70), legend=TRUE, las=2, axis.lty=1)

#I have tried using xpd=FALSE and this works fine withinRguior Rstudio
but not when I plot within devEMF::emf()
barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
"purple"), ylim=c(50,70), legend=TRUE, las=2, axis.lty=1, xpd=FALSE)

I need the emf file to edit the plot.

Why isn't it working with ylim alone? And why doesn't xpd work with emf()?

Thanks in advance for your help,
Stéphanie


mydata <- structure(c(68.1799689328282, 68.2164021637813,
68.3243626415103, 61.7899567386469, 59.5182501049449, 63.9916220705152,
64.1442535260522, 64.2585746423512, 62.5653571705887, 61.631969055001,
61.3991475513249, 63.2401411727188, 65.0488808306348, 63.43022364909,
64.8425577471775, 65.4986231824992, 64.7798619682232, 64.4174790601806,
65.5696701695485, 65.0253962620178, 63.2476885701954, 63.2473647791827,
62.5000542212819, 63.1742307643225, 62.1560658393146, 62.5810636272476,
64.0935149828315, 65.5432025084893, 66.7535104579705, 59.6500997601308,
59.4641686257122, 59.8891527196501, 60.0117050975523, 64.3309521324969,
62.0079305659785, 57.0665210362419, 57.5202118193362, 61.3280531011031,
62.6326634763289, 60.2094259175778, 65.5923786551105, 65.6946445059829,
65.2498254841218, 65.3468620859567, 67.024437492438, 65.8533801964148,
65.0047369761726, 65.0310208374089, 64.3121920326177, 64.8038153143374,
63.7306643056964, 64.2579190762784, 67.5745906026732, 67.0351170775703,
66.4053872920113, 59.9302305698358, 60.368722602391, 60.3572311841096,
60.0960412312049, 63.7886894551889, 62.24708719601, 59.3334729073243,
59.9537485303794, 63.1828096654404, 63.5352778562394, 60.621828397375,
65.8889763819732, 66.2059756115814, 66.4567010911873, 65.8796623180062,
67.5552743734229, 66.504738660398, 66.2085036370622, 66.4230781907321,
65.5130180297911, 65.9051623923225, 64.8408013974267, 65.5175045910169,
68.0760225106606, 66.8615536135711, 65.0390748892256, 59.2940092440695,
60.7061368898884, 59.7345965097738, 59.6019925755588, 63.6011933836225,
62.1134684942427, 60.4227073441121, 60.7834352002706, 63.4539745079728,
63.6329498376672, 58.8034486099638, 65.2910772858539, 65.5952764758513,
65.8371262481454, 66.1191053038481, 67.5230043279325, 66.8569714429862,
66.1045642986574, 66.8499631633452, 66.0121950308609, 66.2593339018511,
65.4397264829666, 65.8389305084859), .Dim = c(26L, 4L), .Dimnames =
list(c("T40", "T41", "T42", "306iv01", "306iv02", "306iv19", "306iv13",
"306iv04", "306iv05", "402iv01", "402iv02", "402iv03", "306iv16",
"306iv10", "TG1", "TG2", "TG3", "TG4", "TG5", "TG6", "TG7", "TG8",
"TG9", "TG10", "TG11", "TG12"), c("L.mean", "L.mean_T1", "L.mean_T2",
"L.mean_T3")))


--
Stéphanie Eyssautier
Ingénieure d'études
Université de REIMS CHAMPAGNE-ARDENNE
Laboratoire GEGENA2
Centre de Recherches en Environnement et Agronomie
2, Esplanade Roland Garros
51100 REIMS

Tél: 03 26 77 36 36
Fax: 03 26 77 36 94

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: ylim in barplot()

David Carlson
If you are using a Windows system, you can Export the plot from RStudio and save it as a metafile without using package devEMF and it will crop the bars with xpd=FALSE. When I used devEMF on a Windows machine, the bars were not cropped with barplot() as you indicated, but when I switched to plotrix::barp() they were cropped. The arguments are a bit different, but I did not need xpd=FALSE:

emf("TestPlot.emf")
barp(t(mydata), col=c("orange", "green", "yellow", "purple"),
ylim=c(50,70), legend.lab=colnames(mydata), legend.pos="topright")
dev.off()

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352


-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of EYSSAUTIER Stéphanie
Sent: Monday, April 25, 2016 9:53 AM
To: [hidden email]
Subject: [R] ylim in barplot()

Dear useRs,

I'm having troubles with using ylim in barplot(): even though I reduce
the y-scale using ylim, the bars still extend down to 0into the x-labels.
The sample data is below, and here is the code.

#This works fine but I would like to plot only from 50 to 70:
barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
"purple"), legend=TRUE, las=2, axis.lty=1)

#This is the ylim version with the bar problem:
barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
"purple"), ylim=c(50,70), legend=TRUE, las=2, axis.lty=1)

#I have tried using xpd=FALSE and this works fine withinRguior Rstudio
but not when I plot within devEMF::emf()
barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
"purple"), ylim=c(50,70), legend=TRUE, las=2, axis.lty=1, xpd=FALSE)

I need the emf file to edit the plot.

Why isn't it working with ylim alone? And why doesn't xpd work with emf()?

Thanks in advance for your help,
Stéphanie


mydata <- structure(c(68.1799689328282, 68.2164021637813,
68.3243626415103, 61.7899567386469, 59.5182501049449, 63.9916220705152,
64.1442535260522, 64.2585746423512, 62.5653571705887, 61.631969055001,
61.3991475513249, 63.2401411727188, 65.0488808306348, 63.43022364909,
64.8425577471775, 65.4986231824992, 64.7798619682232, 64.4174790601806,
65.5696701695485, 65.0253962620178, 63.2476885701954, 63.2473647791827,
62.5000542212819, 63.1742307643225, 62.1560658393146, 62.5810636272476,
64.0935149828315, 65.5432025084893, 66.7535104579705, 59.6500997601308,
59.4641686257122, 59.8891527196501, 60.0117050975523, 64.3309521324969,
62.0079305659785, 57.0665210362419, 57.5202118193362, 61.3280531011031,
62.6326634763289, 60.2094259175778, 65.5923786551105, 65.6946445059829,
65.2498254841218, 65.3468620859567, 67.024437492438, 65.8533801964148,
65.0047369761726, 65.0310208374089, 64.3121920326177, 64.8038153143374,
63.7306643056964, 64.2579190762784, 67.5745906026732, 67.0351170775703,
66.4053872920113, 59.9302305698358, 60.368722602391, 60.3572311841096,
60.0960412312049, 63.7886894551889, 62.24708719601, 59.3334729073243,
59.9537485303794, 63.1828096654404, 63.5352778562394, 60.621828397375,
65.8889763819732, 66.2059756115814, 66.4567010911873, 65.8796623180062,
67.5552743734229, 66.504738660398, 66.2085036370622, 66.4230781907321,
65.5130180297911, 65.9051623923225, 64.8408013974267, 65.5175045910169,
68.0760225106606, 66.8615536135711, 65.0390748892256, 59.2940092440695,
60.7061368898884, 59.7345965097738, 59.6019925755588, 63.6011933836225,
62.1134684942427, 60.4227073441121, 60.7834352002706, 63.4539745079728,
63.6329498376672, 58.8034486099638, 65.2910772858539, 65.5952764758513,
65.8371262481454, 66.1191053038481, 67.5230043279325, 66.8569714429862,
66.1045642986574, 66.8499631633452, 66.0121950308609, 66.2593339018511,
65.4397264829666, 65.8389305084859), .Dim = c(26L, 4L), .Dimnames =
list(c("T40", "T41", "T42", "306iv01", "306iv02", "306iv19", "306iv13",
"306iv04", "306iv05", "402iv01", "402iv02", "402iv03", "306iv16",
"306iv10", "TG1", "TG2", "TG3", "TG4", "TG5", "TG6", "TG7", "TG8",
"TG9", "TG10", "TG11", "TG12"), c("L.mean", "L.mean_T1", "L.mean_T2",
"L.mean_T3")))


--
Stéphanie Eyssautier
Ingénieure d'études
Université de REIMS CHAMPAGNE-ARDENNE
Laboratoire GEGENA2
Centre de Recherches en Environnement et Agronomie
2, Esplanade Roland Garros
51100 REIMS

Tél: 03 26 77 36 36
Fax: 03 26 77 36 94

______________________________________________
[hidden email] 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.
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: ylim in barplot()

Ivan Calandra-4
Thank you David,

That's a nice workaround using plotrix::barp(), but that doesn't explain
why ylim doesn't work as intended (or at least, as I expect it to work),
or why xpd has no influence when using devEMF::emf()...

The problem with saving directly in RStudio is that it requires to
manually save the plot, and this becomes troublesome when there are a
lot of plot commands in a single script.

Bests,
Ivan (on behalf of Stéphanie)

--
Ivan Calandra, PhD
Scientific Mediator
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
[hidden email]
--
https://www.researchgate.net/profile/Ivan_Calandra
https://publons.com/author/705639/

Le 25/04/2016 21:16, David L Carlson a écrit :

> If you are using a Windows system, you can Export the plot from RStudio and save it as a metafile without using package devEMF and it will crop the bars with xpd=FALSE. When I used devEMF on a Windows machine, the bars were not cropped with barplot() as you indicated, but when I switched to plotrix::barp() they were cropped. The arguments are a bit different, but I did not need xpd=FALSE:
>
> emf("TestPlot.emf")
> barp(t(mydata), col=c("orange", "green", "yellow", "purple"),
> ylim=c(50,70), legend.lab=colnames(mydata), legend.pos="topright")
> dev.off()
>
> -------------------------------------
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
>
>
> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of EYSSAUTIER Stéphanie
> Sent: Monday, April 25, 2016 9:53 AM
> To: [hidden email]
> Subject: [R] ylim in barplot()
>
> Dear useRs,
>
> I'm having troubles with using ylim in barplot(): even though I reduce
> the y-scale using ylim, the bars still extend down to 0into the x-labels.
> The sample data is below, and here is the code.
>
> #This works fine but I would like to plot only from 50 to 70:
> barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
> "purple"), legend=TRUE, las=2, axis.lty=1)
>
> #This is the ylim version with the bar problem:
> barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
> "purple"), ylim=c(50,70), legend=TRUE, las=2, axis.lty=1)
>
> #I have tried using xpd=FALSE and this works fine withinRguior Rstudio
> but not when I plot within devEMF::emf()
> barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
> "purple"), ylim=c(50,70), legend=TRUE, las=2, axis.lty=1, xpd=FALSE)
>
> I need the emf file to edit the plot.
>
> Why isn't it working with ylim alone? And why doesn't xpd work with emf()?
>
> Thanks in advance for your help,
> Stéphanie
>
>
> mydata <- structure(c(68.1799689328282, 68.2164021637813,
> 68.3243626415103, 61.7899567386469, 59.5182501049449, 63.9916220705152,
> 64.1442535260522, 64.2585746423512, 62.5653571705887, 61.631969055001,
> 61.3991475513249, 63.2401411727188, 65.0488808306348, 63.43022364909,
> 64.8425577471775, 65.4986231824992, 64.7798619682232, 64.4174790601806,
> 65.5696701695485, 65.0253962620178, 63.2476885701954, 63.2473647791827,
> 62.5000542212819, 63.1742307643225, 62.1560658393146, 62.5810636272476,
> 64.0935149828315, 65.5432025084893, 66.7535104579705, 59.6500997601308,
> 59.4641686257122, 59.8891527196501, 60.0117050975523, 64.3309521324969,
> 62.0079305659785, 57.0665210362419, 57.5202118193362, 61.3280531011031,
> 62.6326634763289, 60.2094259175778, 65.5923786551105, 65.6946445059829,
> 65.2498254841218, 65.3468620859567, 67.024437492438, 65.8533801964148,
> 65.0047369761726, 65.0310208374089, 64.3121920326177, 64.8038153143374,
> 63.7306643056964, 64.2579190762784, 67.5745906026732, 67.0351170775703,
> 66.4053872920113, 59.9302305698358, 60.368722602391, 60.3572311841096,
> 60.0960412312049, 63.7886894551889, 62.24708719601, 59.3334729073243,
> 59.9537485303794, 63.1828096654404, 63.5352778562394, 60.621828397375,
> 65.8889763819732, 66.2059756115814, 66.4567010911873, 65.8796623180062,
> 67.5552743734229, 66.504738660398, 66.2085036370622, 66.4230781907321,
> 65.5130180297911, 65.9051623923225, 64.8408013974267, 65.5175045910169,
> 68.0760225106606, 66.8615536135711, 65.0390748892256, 59.2940092440695,
> 60.7061368898884, 59.7345965097738, 59.6019925755588, 63.6011933836225,
> 62.1134684942427, 60.4227073441121, 60.7834352002706, 63.4539745079728,
> 63.6329498376672, 58.8034486099638, 65.2910772858539, 65.5952764758513,
> 65.8371262481454, 66.1191053038481, 67.5230043279325, 66.8569714429862,
> 66.1045642986574, 66.8499631633452, 66.0121950308609, 66.2593339018511,
> 65.4397264829666, 65.8389305084859), .Dim = c(26L, 4L), .Dimnames =
> list(c("T40", "T41", "T42", "306iv01", "306iv02", "306iv19", "306iv13",
> "306iv04", "306iv05", "402iv01", "402iv02", "402iv03", "306iv16",
> "306iv10", "TG1", "TG2", "TG3", "TG4", "TG5", "TG6", "TG7", "TG8",
> "TG9", "TG10", "TG11", "TG12"), c("L.mean", "L.mean_T1", "L.mean_T2",
> "L.mean_T3")))
>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: ylim in barplot()

Ivan Calandra-4
Dear useRs,

It seems that my last e-mail went quite unnoticed...
Has anyone an idea about ylim doesn't work in barplot (see details below)?

Thank you in advance,
Ivan (on behalf of Stéphanie)

--
Ivan Calandra, PhD
Scientific Mediator
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
[hidden email]
--
https://www.researchgate.net/profile/Ivan_Calandra
https://publons.com/author/705639/

Le 26/04/2016 à 08:41, Ivan Calandra a écrit :

> Thank you David,
>
> That's a nice workaround using plotrix::barp(), but that doesn't
> explain why ylim doesn't work as intended (or at least, as I expect it
> to work), or why xpd has no influence when using devEMF::emf()...
>
> The problem with saving directly in RStudio is that it requires to
> manually save the plot, and this becomes troublesome when there are a
> lot of plot commands in a single script.
>
> Bests,
> Ivan (on behalf of Stéphanie)
>
> --
> Ivan Calandra, PhD
> Scientific Mediator
> University of Reims Champagne-Ardenne
> GEGENAA - EA 3795
> CREA - 2 esplanade Roland Garros
> 51100 Reims, France
> +33(0)3 26 77 36 89
> [hidden email]
> --
> https://www.researchgate.net/profile/Ivan_Calandra
> https://publons.com/author/705639/
>
> Le 25/04/2016 21:16, David L Carlson a écrit :
>> If you are using a Windows system, you can Export the plot from
>> RStudio and save it as a metafile without using package devEMF and it
>> will crop the bars with xpd=FALSE. When I used devEMF on a Windows
>> machine, the bars were not cropped with barplot() as you indicated,
>> but when I switched to plotrix::barp() they were cropped. The
>> arguments are a bit different, but I did not need xpd=FALSE:
>>
>> emf("TestPlot.emf")
>> barp(t(mydata), col=c("orange", "green", "yellow", "purple"),
>> ylim=c(50,70), legend.lab=colnames(mydata), legend.pos="topright")
>> dev.off()
>>
>> -------------------------------------
>> David L Carlson
>> Department of Anthropology
>> Texas A&M University
>> College Station, TX 77840-4352
>>
>>
>> -----Original Message-----
>> From: R-help [mailto:[hidden email]] On Behalf Of
>> EYSSAUTIER Stéphanie
>> Sent: Monday, April 25, 2016 9:53 AM
>> To: [hidden email]
>> Subject: [R] ylim in barplot()
>>
>> Dear useRs,
>>
>> I'm having troubles with using ylim in barplot(): even though I reduce
>> the y-scale using ylim, the bars still extend down to 0into the
>> x-labels.
>> The sample data is below, and here is the code.
>>
>> #This works fine but I would like to plot only from 50 to 70:
>> barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
>> "purple"), legend=TRUE, las=2, axis.lty=1)
>>
>> #This is the ylim version with the bar problem:
>> barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
>> "purple"), ylim=c(50,70), legend=TRUE, las=2, axis.lty=1)
>>
>> #I have tried using xpd=FALSE and this works fine withinRguior Rstudio
>> but not when I plot within devEMF::emf()
>> barplot(t(mydata), beside=TRUE, col=c("orange", "green", "yellow",
>> "purple"), ylim=c(50,70), legend=TRUE, las=2, axis.lty=1, xpd=FALSE)
>>
>> I need the emf file to edit the plot.
>>
>> Why isn't it working with ylim alone? And why doesn't xpd work with
>> emf()?
>>
>> Thanks in advance for your help,
>> Stéphanie
>>
>>
>> mydata <- structure(c(68.1799689328282, 68.2164021637813,
>> 68.3243626415103, 61.7899567386469, 59.5182501049449, 63.9916220705152,
>> 64.1442535260522, 64.2585746423512, 62.5653571705887, 61.631969055001,
>> 61.3991475513249, 63.2401411727188, 65.0488808306348, 63.43022364909,
>> 64.8425577471775, 65.4986231824992, 64.7798619682232, 64.4174790601806,
>> 65.5696701695485, 65.0253962620178, 63.2476885701954, 63.2473647791827,
>> 62.5000542212819, 63.1742307643225, 62.1560658393146, 62.5810636272476,
>> 64.0935149828315, 65.5432025084893, 66.7535104579705, 59.6500997601308,
>> 59.4641686257122, 59.8891527196501, 60.0117050975523, 64.3309521324969,
>> 62.0079305659785, 57.0665210362419, 57.5202118193362, 61.3280531011031,
>> 62.6326634763289, 60.2094259175778, 65.5923786551105, 65.6946445059829,
>> 65.2498254841218, 65.3468620859567, 67.024437492438, 65.8533801964148,
>> 65.0047369761726, 65.0310208374089, 64.3121920326177, 64.8038153143374,
>> 63.7306643056964, 64.2579190762784, 67.5745906026732, 67.0351170775703,
>> 66.4053872920113, 59.9302305698358, 60.368722602391, 60.3572311841096,
>> 60.0960412312049, 63.7886894551889, 62.24708719601, 59.3334729073243,
>> 59.9537485303794, 63.1828096654404, 63.5352778562394, 60.621828397375,
>> 65.8889763819732, 66.2059756115814, 66.4567010911873, 65.8796623180062,
>> 67.5552743734229, 66.504738660398, 66.2085036370622, 66.4230781907321,
>> 65.5130180297911, 65.9051623923225, 64.8408013974267, 65.5175045910169,
>> 68.0760225106606, 66.8615536135711, 65.0390748892256, 59.2940092440695,
>> 60.7061368898884, 59.7345965097738, 59.6019925755588, 63.6011933836225,
>> 62.1134684942427, 60.4227073441121, 60.7834352002706, 63.4539745079728,
>> 63.6329498376672, 58.8034486099638, 65.2910772858539, 65.5952764758513,
>> 65.8371262481454, 66.1191053038481, 67.5230043279325, 66.8569714429862,
>> 66.1045642986574, 66.8499631633452, 66.0121950308609, 66.2593339018511,
>> 65.4397264829666, 65.8389305084859), .Dim = c(26L, 4L), .Dimnames =
>> list(c("T40", "T41", "T42", "306iv01", "306iv02", "306iv19", "306iv13",
>> "306iv04", "306iv05", "402iv01", "402iv02", "402iv03", "306iv16",
>> "306iv10", "TG1", "TG2", "TG3", "TG4", "TG5", "TG6", "TG7", "TG8",
>> "TG9", "TG10", "TG11", "TG12"), c("L.mean", "L.mean_T1", "L.mean_T2",
>> "L.mean_T3")))
>>
>>
>

______________________________________________
[hidden email] 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.