I want to make a "timeline" using a stacked column chart. What I want to do is to remove all background so I just have a bar and nothing else. I am stuck with the white background of the chart.
Here is a minimal example:
mytheme <- theme(
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
#panel.background = element_blank()
)
Name <- c("One", "Two", "Three", "Four")
value <- c(2, 5, 7, 8)
df <- data.frame(Name, value)
ggplot(df)+
aes(x= "Name", y = value, fill = Name) +
geom_col(width = .1, show.legend = FALSE) +
xlab("") + ylab("") +
coord_flip() +
mytheme
giving me a bar but on a big background .
(I have commented out the panel.background
just to show the extent of the background. I want to "crop" that white background so I have only the bar or just a little space around the bar. Help pls.
Update
After the suggestion by @Gregor, I modified the code ggplot
as follows:
ggplot(df)+
aes(x= "Name", y = value, fill = Name) +
geom_col(width = .1, show.legend = FALSE) +
xlab("") + ylab("") +
coord_flip(expand = FALSE) +
mytheme
The result is a very wide bar (tall on page because I have used coord_flip):
All I need to do now is to reduce the height (as it is seen in the picture) to make it more like my original bar. How can I change that?
Solution
I finally found a simple solution. As I am using R Markdown
, I used:
```{r, ..., fig.width=4, fig.height=.3}
in the preamble to the embedded figure. Not the best solution, but it works. Thanks to all.