Change the y axis length for boxplots with R [closed] - r

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
is there a way to increase the y axis length to the maximun value?
When I use this code:
par(mfrow=c(3,5))
for (i in c("mrts","p100e10","p75","PIA","pop1076","pop1616","pop2911","pop500","pop800","rev84","SugarCaneFarms","Swiss","USbanks","UScities","UScolleges"))
{
boxplot(dados[[i]],xlab=i)
}
But then it appears boxplots with a low y axis. I need to change the y axis but I didnt want to change one by one, I want to appear the last value.
Boxplots
How Can I do that?
If it is not possible, how can I do it one by one?
Thanks

You can specify ylim with the minimal and maximal values of the y axis.
In your example:
boxplot(dados[[i]],xlab=i,ylim=c(min(dados[[i]]),max(dados[[i]])))

ylim=c(-min,max)
It's a corollary of xlim and should solve your issue.

Related

scale_fill_manual() not respected [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 days ago.
Improve this question
I'm trying to create a geom_rect plot with rectangle coloring depending on a cell value. So far is working but when I try to change the default coloring the the ones I want nothing happens.
Color should depends on a value that can be a number from 1 to 3.
Here is the code that I have so far:
colors=c("2"="gray","1"="green","3"="blue")
plot = ggplot()+ geom_rect(data=test[[1]],mapping=aes(xmin=test[[1]][,2]-0.40,xmax=test[[1]][,2]+0.40,ymin=test[[1]][,3],ymax=test[[1]][,4]),fill=(test[[1]]$`Significant Results`+2))
plot + scale_fill_manual(values=colors)
This gives the plot like I want but with different fill colors. It seems that scale_fill_manual() is not respected.
When I run the code I get this message:
"Scale for fill is already present.
Adding another scale for fill, which will replace the existing scale."
Which is expected but the colors do not change at all.
I have tried using different colors but still I have the same problem.

R plot function: Increase size of legend scale tick labels [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am using plot() for some raster images. I want to increase the size of the legend scale tick labels. Any ideas?
Following the documentation for raster::plot(), any extra parameters passed to it are passed to fields::image.plot(). See: image.plot
Based on the answer to this: Increase font size in legend of image.plot, you should be able to pass
axis.args = list(cex.axis = font_size)
as a parameter to your call to plot() to change the legend tick label size.

How to position the plot legend outside the plot in the bottom-right [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm using the latest ggplot2 and currently do p + theme(legend.position='right'). The function theme is well documented and combining bottom and right doesn't seem possible. However, maybe there is an alternate way to achieve this?
You can use 2-element numeric vector for the position, something like:
p+theme(legend.position=c(0.85,0)
The problem is, it will overlap the plotting area.
And if you want to force it to be in one horizontal line, you can add:
p+guides(fill = guide_legend(nrow = 1))
EDIT
I used plot.margin to expand the area at the bottom, you can play with the parameters:
p+
guides(fill = guide_legend(nrow = 1))+
theme(plot.margin=unit(c(1,1,4,0.5),"cm"))+
theme(legend.position=c(0.85,-0.7))
OR
p+
theme(plot.margin=unit(c(1,1,4,0.5),"cm")) +
theme(legend.position=c(0.85,-0.7))
NOTE
Using Rstudio, when I export the image at certain width*height I don't get the legends, but if I drag and adjust the view before exporting as follows, it works.

How to customize notches in ggplot boxplot [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I had a question on how to change/customize the upper and lower limit of a notch on a boxplot created by ggplot2. I looked through the function stat_boxplot and found that ggplot calculates the notch limits with the equation median +/- 1.58 * iqr / sqrt(n). However instead of that equation I wanted to change it with my own set of upper and lower notch limits.
My data has 4 factors and for each factor I calculated the median and did a bootstrap to get a 95% confidence interval of that median. Thus in the end I would like to change every boxplot to have its own unique notch upper and lower limit.
I'm not sure if this is even possible in ggplot and was wondering if people have an idea on how to do this?
Thanks again!
I've figured out one way to customize the notches on a plot using ggplot with the function ggplot_build.
After plotting a boxplot with say:
p<-ggplot(combined,aes(x=foo,y=bar)) + geom_boxplot(notch=TRUE)
not really sure what exactly happens with ggplot_build but seems like it converts the plot into a data-frame ish structure so one can manipulate it if wanted.
gg<-ggplot_build(p)
afterwards:
gg$data[[1]]$notchlower
gg$data[[1]]$notchupper
contains the notch limits for your plot and you can basically change it with something like:
gg$data[[1]]$notchlower<-50
gg$data[[1]]$notchupper<-100
And if you had mulitple boxplots and wanted to individually change each boxplot:
gg$data[[1]]$notchlower[1]<-50
gg$data[[1]]$notchlower[2]<-50
....
gg$data[[1]]$notchlower[n]<-50
gg$data[[1]]$notchupper[1]<-100
gg$data[[1]]$notchupper[2]<-100
....
gg$data[[1]]$notchupper[n]<-100
Anyways hopefully this is a valid method to do and it would be of help for other people.

R - Symmetry with hexbin [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I plot two hexbin graphs with R (with package 'hexbin') from data file with two columns gr and ug.
The first plot : gr as a function of ug
The second plot : ug as a fonction of gr
Why aren't they perfectly symmetrical?
Thanks in advance
Notice that in both cases the hexagons are oriented to have 2 sides vertical and no sides horizontal. To be perfectly symmetric one of the plots would need to have the rotated hexagons (2 sides horizontal).
So the binning is slightly different between the 2 graphs and points that are near the boundary in the 1st plot may fall into a different cell (symmetrically) in the 2nd plot. So while the 2 plots are similar overall you will see some minor differences due to how the data is binned.
This is true in general for plots/techniques that depend on binning continuous data, a slight change to how the binning is done will results in usually minor changes in the results. It is good to do multiple plots with small changes to the options that determine the binning to see how much things change.

Resources