logo
down
shadow

How to use 'par' for manipulating plot margins?


How to use 'par' for manipulating plot margins?

Content Index :

How to use 'par' for manipulating plot margins?
Tag : r , By : Marie Ramos
Date : November 23 2020, 03:01 PM

Any of those help In R base graphs, there is an option in par to use "pretty" margins. This default option extends the data range on the axis values by 4% for pretty labels. This has the side effect of ignoring xlim and ylim sometimes.
One thing to try is to switch this option to use exactly the data range. The options are xaxs="i" and yaxs="i" for X and Y axes, respectively.
Betadisp<-data.frame(distances=
                       c(0.171774954519456, 
                           0.0623868535364207, 0.0621507889963585, 0.0869573133495299, 
                           0.0169233135900547, 0.0080384125007011, 0.173187193386872, 
                           0.175566607202207, 0.263873649177415, 0.269596668079633, 
                           0.309083021546677, 0.114187871090147, 0.124154597704232, 
                           0.295532192696357, 0.333332176352344, 0.218105548195935, 
                           0.00291069847495801, 0.380347922295584, 0.0050168867788829, 
                           0.285763501850193, 0.190753345691698, 0.122265556127451, 
                           0.108666519108659, 0.29755013745441, 0.0467048709645198, 
                           0.0186762875503434, 0.16133848141303, 0.138430730434188, 
                           0.297991278634962, 0.168844071561681, 0.160066867257958, 
                           0.171285258028997, 0.0159658923646438, 0.239593234480484, 
                           0.11149382715073, 0.150842075345091, 0.142565290934167, 0.0838881561641354, 
                           0.110208116588627, 0.105737052071915, 0.156385076275321, 
                           0.045244914460967, 0.206865801853543, 0.0183152170680244, 
                           0.159206217954337, 0.277843809072997, 0.0888342965374933, 
                           0.315721981172762, 0.204295902587072, 0.12797501136046, 0.185151760663692, 
                           0.220301416680961, 0.195629716424938, 0.170000042629844, 
                           0.144764318702658, 0.0982423159776023, 0.077784806093838, 
                           0.200974730859957, 0.0474174597287366, 0.119811361544433, 
                           0.0872631008364077, 0.147577189165856, 0.0672150078204365, 
                           0.0655639372667505, 0.147983825716124, 0.13939190413907, 
                           0.0839168256483553, 0.0110682447772202, 0.0804055775665854, 
                           0.0643234769159, 0.152687458838593, 0.286371553538374, 0.0901197325885831, 
                           0.153693904513509, 0.0957030433961639, 0.0105961602592448, 
                           0.320362093692189, 0.0932809343859479, 0.0878333741087963, 
                           0.0770368040506406, 0.0959749515319617, 0.0332807667898261, 
                           0.191933577147619, 0.0787686840490281, 0.0496881262302877, 
                           0.0485530197564093, 0.112560776469416, 0.0874930322963143, 
                           0.203908196211518, 0.0418832585552037, 0.0581386263146353, 
                           0.0105720607945607, 0.115237490805503, 0.0156632717717389, 
                           0.0914369812138262, 0.140451490489812, 0.0539609303513526, 
                           0.259669347645691, 0.0667734806834846, 0.0058207347089303, 
                           0.162226558213165, 0.103192578557601, 0.0165544329655469, 
                           0.0356738544468149, 0.248033053584017, 0.348663085500656, 
                           0.281938256010966, 0.019572401013719, 0.0149422179335055, 
                           0.174230363870647, 0.0968716024168187, 0.106430191879212, 
                           0.197156957697445, 0.157750474524708, 0.319388997989459, 
                           0.084827956591434, 0.0316429009940913, 0.0853248197344982, 
                           0.207212676963987, 0.294795451892385, 0.141659679876788, 
                           0.128895058876958, 0.0530746007081779, 0.439797839061484, 
                           0.171106056872192, 0.141062546211989, 0.00257102000838311, 
                           0.00514544376441906, 0.000715985216287402, 0.191666109378775, 
                           0.12585928374854, 0.0559321404138331, 0.590852809920102, 
                           0.274161403213926, 0.344444029816024, 0.051074623626536, 
                           0.187006960782375, 0.0627044610324955, 0.00271511733050407),
                     group=c(3, 
                             3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
                             3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
                             3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
                             3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
                             2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
                             2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
                             2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
                             1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
                             1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
                             1, 1, 1)
                       )
Betadisp$group<-factor(Betadisp$group,levels=c("3","2","1"))
boxplot(Betadisp$distances ~ Betadisp$group, col=c("darkgreen", "blue", "red"), 
boxwex=0.4, outline=T, ylim=c(0, 0.46), xlim=c(0.75,3.25), names = c("OG", "LIL","HIL"), 
cex.lab=1.5, ylab="Distance to centroid", xlab='x', las = 1, notch=F, axis=T)
boxplot(Betadisp$distances ~ Betadisp$group, col=c("darkgreen", "blue", "red"), boxwex=0.4, 
outline=T, ylim=c(0, 0.46), xlim=c(0.75,3.25), names = c("OG", "LIL","HIL"), 
cex.lab=1.5, ylab="Distance to centroid", xlab='x', las = 1, notch=F, axis=T, 
xaxs="i",yaxs="i")

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How can I remove plot margins between the axes of the plot and the plot contents in R?


Tag : r , By : CrimsonGore
Date : March 29 2020, 07:55 AM
To fix this issue Look at the parameters xaxs and yaxs (under ?par). By default the axis contains the data range plus 4% on either side. If you override the parameter, then you can get an axis exactly equal to the data range. Cf:
> curve(x^2)

> curve(x^2, xaxs="i", yaxs="i")

Trouble with margins & plot sizes in multiple figure plot in pdf


Tag : r , By : Trevor Cortez
Date : March 29 2020, 07:55 AM
I hope this helps you . My general recommendations would be to (1) stick to only one unit of measurement, inches or lines, and (2) do some arithmetic to determine how big your device size needs to be to fit what you're plotting.
You're mixing mar and pin which use lines and inches. I certainly don't know how tall 1 inch plus 1 line is going to be off the top of my head (although I'm sure we could hack something together to calculate it).
pdf(file="My pdf.pdf", paper="letter",width = 7,height = 10)
  par(mfrow=c(2,1), mai=c(1,0.5,0.5,0.25), pin=c(3,3))
  hist(x, freq=FALSE)
  lines(density(x))
  qqnorm(x)
dev.off()

Rmarkdown to pdf: change plot margins without showing the code resposible for changing the margins


Tag : r , By : greggerz
Date : March 29 2020, 07:55 AM
help you fix your problem From knitr docs.

How to plot multiple SpatialLines on the same plot: Error in plot.new() : figure margins too large


Tag : r , By : TomL
Date : March 29 2020, 07:55 AM
Hope that helps I sometimes get this error as well and I maximize my X11 plotting window and it goes away (I don't use RStudio often though). The code you provided works fine for me even in the default size viewer. This code produces 3 plots though. You could make them on the same plot by using the parameter new in par
plot(spl)
par(new=TRUE)
plot(spl90)
par(new=TRUE)
plot(spl180)
par(new=FALSE)

Error in plot.new() : figure margins too large, Scatter plot


Tag : r , By : pdkent
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • How to divide each of a range a variables by a second range of variables in R
  • Why do I need to assemble vector before scaling in Spark?
  • How to select individuals which appear in multiple groups?
  • How can I fill columns based on values in another column?
  • 32 bit R and 64 bit R: output differs
  • Remove a single backslash in paste0 output
  • ggplot2 different label for the first break
  • TSP in R, with given distances
  • How to find the given value from the range of values?
  • Solution on R group by issue _ multiple combination
  • Transform multiple columns with a function that uses different arguments per column
  • How can I parse a string with the format "1/16/2019 1:24:51" into a POSIXct or other date variable?
  • How to plot a box plot in R for outlier detection for a huge number of rows?
  • How to change column name according to another dataframe in R?
  • `sjPlot::tab_df()`--how to set the number of decimal places?
  • time average for specific time range in r
  • joining dataframes by closest time and another key in r
  • How to create nested for loop for a certain range
  • New category based on sequence of date ranges
  • how to extract formula from coxph model summary in R?
  • add row based on variable condition in R
  • Generating the sequence 111122222333334
  • Unable to use has_goog_key() in R
  • how to multiply each row with a scaler in corresponding column?
  • R is not recognizing levels of a factor as the same. Is there a way to do this?
  • Calculating mean of replicate experiment result values in a column based on multiple columns using R
  • Best method to extract the first instance of a string between specified keywords using data.table
  • ignore optional combination of alphanumeric characters in str_extract
  • Why tracemem shows two copies when modification occurs inside function body?
  • Can't use mppm on multitype point patterns
  • How to move selected matrix rows to top of matrix based on a selection vector of row names
  • Combining expressions with a common operator
  • Passing string through multiple filters for matching
  • Convert two columns in R to rows of unique occurrence
  • How to create a dataframe using a function based on user-input?
  • How to access the visited vertices in a given shortest path using R igraph
  • Differences in Unicode character output with print()
  • Extracting Function or Objects from a String and then Piping Them with Magrittr/Dplyr
  • renderUI not evaluated until it is rendered
  • Find the maximum absolute value by row in an R data frame
  • Extracting data from irregular lists using purrr:map()
  • transforming data based on range of column in r
  • Identify and subset rows with some similar information
  • converting character from mongolite to timestamp in R
  • Create list from two vectors with every combo of each
  • Error in running a spread because of unique 'key combinations'; combining rows of data
  • visualize numerical strings as a matrixed heatmap
  • how to make a blocked matrix?
  • How to summarize with two functions using with dplyr
  • Dataframe is no longer the same after being saved to Excel and read back in
  • Create duplicate rows using based on availability of data
  • Keep empty groups when grouping with data.table in R
  • Grouping of Event Time Data based on multiple, iterative conditions
  • Formatting Numbers in Flextable for Specific Columns
  • How to store results from for-loop into a dataframe
  • How to select the values in my dataframe which has logical operator "<" (less than), divide them by two, an
  • Rowwise extract data between two strings
  • Convert a string separate by . and +
  • stacking function for values in R
  • dplyr coerces characters to factors
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com