How can I increase the padding around the plot?


it

I have a horizontal bar chart with too tight padding:

data <- data.frame(month = factor(c("Nov", "Dec", "Jan", "Feb")),
                   count = c(1489, 788, 823, 1002))

g <- (ggplot2::ggplot(data, ggplot2::aes(x=month, y=count)) +
        ggplot2::geom_col() +
        ggplot2::scale_x_discrete(limits=rev(data$month)) +
        ggplot2::coord_flip()) +

g

Horizontal bar chart with too tight padding

I'm happy with the spacing between the bars, but I'd like more space around the stack of 4 bars. In other words, I want to add more padding around the 4-column chart in the center. The light gray rectangular area used as the background for the 4-cell stack should remain the same, but the size of the 4-cell stack within that rectangle should shrink, resulting in the net effect of creating a wider padding around the 4-cell. -Bar stacks; in other words, more light grey backgrounds will be seen around the 4 chimneys.

Also, I'm looking for ways to be completely independent of the actual values ​​on the axes. The code should produce the same visual effect whether the x range is 0-1500 or 0-1500000 or completely non-numeric (i.e. categorical).

This means that the following additional padding must be specified: (a) as a percentage of the total width and height of the figure; or (b) a fixed number of pixels; or (c) a fixed unit of measure (cm, inches, print points, etc.).

Finally, ideally , I'd like to be able to specify padding separately for all four edges.

How can I do this?

IMPORTANT I don't want to increase the margins around the light grey background . I want to increase the padding inside the light grey background . If this distinction is unclear, see this .

heds1

You can use the function within the parameter of expand_scalethe -type function. A bit wordy, but...expandscale_x_continuous

ggplot(data, aes(x=month,y=count)) +
    geom_bar(stat="identity") + 
    scale_x_discrete(limits=(data$month), expand=expand_scale(mult=c(0.5,0.5))) + 
    geom_text(aes(label=count), hjust=-0.3) +
    coord_flip() + scale_y_continuous(expand=expand_scale(mult=c(0.5,0.5)))

Play with the two elements of the steering multvector , which define the padding above and below the axis, so you can change each side of the plot independently (though it's not fully transparent and would be a little trickier). See ?expand_scalefor more information.

enter image description here

Related


How can I increase the padding around the plot?

it I have a horizontal bar chart with too tight padding: data <- data.frame(month = factor(c("Nov", "Dec", "Jan", "Feb")), count = c(1489, 788, 823, 1002)) g <- (ggplot2::ggplot(data, ggplot2::aes(x=month, y=count)) + ggplot2::geom_

How can I increase the padding around the plot?

it I have a horizontal bar chart with too tight padding: data <- data.frame(month = factor(c("Nov", "Dec", "Jan", "Feb")), count = c(1489, 788, 823, 1002)) g <- (ggplot2::ggplot(data, ggplot2::aes(x=month, y=count)) + ggplot2::geom_

How can I increase the padding in each iteration?

no What I want is to add padding-left to increase by 15px for each iteration. Any suggestions what should I do? So far this is what I have. getClassByValue(index){ return { 'padding-left': 15 * index + 'px' } } <div class="ui-g-2" [ngClass]=

How can I increase the padding in each iteration?

no What I want is to add padding-left to increase by 15px for each iteration. Any suggestions what should I do? So far this is what I have. getClassByValue(index){ return { 'padding-left': 15 * index + 'px' } } <div class="ui-g-2" [ngClass]=

How can I increase the padding in each iteration?

no What I want is to add padding-left to increase by 15px for each iteration. Any suggestions what should I do? So far this is what I have. getClassByValue(index){ return { 'padding-left': 15 * index + 'px' } } <div class="ui-g-2" [ngClass]=

How can I increase the padding in each iteration?

No What I want is to add padding-left to increase by 15px for each iteration. Any suggestions what should I do? So far this is what I have. getClassByValue(index){ return { 'padding-left': 15 * index + 'px' } } <div class="ui-g-2" [ngClass]=

How to increase padding around an image in Jekyll

Matt Sosner I have a Jekyll blog with GitHub pages and I'm having an issue where images embedded in blog posts don't have any padding, meaning the text is too close to the image: I want to specify the padding in the style.scssfile so I can apply it to all imag

How to increase padding around an image in Jekyll

Matt Sosner I have a Jekyll blog with GitHub Pages and I'm running into an issue where images embedded in blog posts don't have any padding, meaning the text is too close to the image: I want to specify the padding in the style.scssfile so I can apply it to al

How to increase padding around an image in Jekyll

Matt Sosner I have a Jekyll blog with GitHub Pages and I'm running into an issue where images embedded in blog posts don't have any padding, meaning the text is too close to the image: I want to specify the padding in the style.scssfile so I can apply it to al

How to increase padding around an image in Jekyll

Matt Sosner I have a Jekyll blog with GitHub Pages and I'm running into an issue where images embedded in blog posts don't have any padding, meaning the text is too close to the image: I want to specify the padding in the style.scssfile so I can apply it to al

How to increase padding around an image in Jekyll

Matt Sosner I have a Jekyll blog with GitHub Pages and I'm running into an issue where images embedded in blog posts don't have any padding, meaning the text is too close to the image: I want to specify the padding in the style.scssfile so I can apply it to al

How can I remove the padding around the background image?

Vincent How can I remove the "padding" around the background image? Here is a demo : https://jsbin.com/dobucizaqi/edit?html,css,output .foo { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox=

How can I remove the padding around the background image?

Vincent How can I remove the "padding" around the background image? Here is a demo : https://jsbin.com/dobucizaqi/edit?html,css,output .foo { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox=

How can I remove the padding around the background image?

Vincent How can I remove the "padding" around the background image? Here is a demo : https://jsbin.com/dobucizaqi/edit?html,css,output .foo { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox=