1
votes

I have searched a lot about this topic. I found many Threads about it.

But none of it fits to my Problem, cause most of them want to change window size or device size. Also if you use the pdf() function in R.

I'm using RSweave to build a pdf file. I tried working with "xlim" or "space" attribute.

Both of them not change the width or space in the Plot Area, just the width of the bars.

I also tried to work with par(mfrow) but that doesnt help me either.

I dont want to change the margin around the Plot Area. I want to make the Plot Area wider, because the title of the bars dissapeared, because there is no space.

Here is the code for the plot (remeber it's in a RSweave document):

<<echo=FALSE, fig=TRUE>>== 
plot(data$SD03, names.arg =c("0-15","15-19","20-24","25-29","30-34",
"35-39","40-44","45- 49","50-54","55-59","60-64","65 Jahre oder Älter"))
# xlim=c(0, 70), space=5
@

And a Screenshot of the result:

enter image description here

Hope you can help me, thanks for answers!

1

1 Answers

1
votes

Not being as familiar with base R graphics, I offer a ggplot2 solution (based on guessing the values from your screen shot):

library(ggplot2)

value <- c(0, 1, 20, 3, 3, 0, 0, 5, 2, 5, 2, 7)
names.arg =c("0-15","15-19","20-24","25-29","30-34",
             "35-39","40-44","45- 49","50-54","55-59","60-64","65 Jahre oder Älter")
df <- data.frame(names.arg = names.arg, value = value)

ggplot(df, aes(x = names.arg, y = value)) + 
  geom_bar(stat = "identity", fill = "cadetblue", width = 0.9) +
  theme(axis.text.x = element_text(angle = 30)) +
  theme(axis.ticks.x = element_blank()) +
  labs(x = NULL, y = NULL) +
  scale_x_discrete(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0,0))

enter image description here