[r] Reduce size of legend area in barplot

I can't reduce the size of the legend in this plot. Could someone help me out? I want it to appear topright, but with no more than 20% of the height of plot area

a <- c(3, 2, 2, 2, 1, 2 )
barplot(a, beside = T,
col = 1:6, space = c(0, 2))
legend("topright", legend = c("a", "b", "c", "d", "e", "f"), fill = 1:6, ncol = 2)

This question is related to r plot legend

The answer is


The cex parameter will do that for you.

a <- c(3, 2, 2, 2, 1, 2 )
barplot(a, beside = T,
        col = 1:6, space = c(0, 2))
legend("topright", 
       legend = c("a", "b", "c", "d", "e", "f"), 
       fill = 1:6, ncol = 2,
       cex = 0.75)

The plot


Examples related to r

How to get AIC from Conway–Maxwell-Poisson regression via COM-poisson package in R? R : how to simply repeat a command? session not created: This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium How to show code but hide output in RMarkdown? remove kernel on jupyter notebook Function to calculate R2 (R-squared) in R Center Plot title in ggplot2 R ggplot2: stat_count() must not be used with a y aesthetic error in Bar graph R multiple conditions in if statement What does "The following object is masked from 'package:xxx'" mean?

Examples related to plot

Fine control over the font size in Seaborn plots for academic papers Why do many examples use `fig, ax = plt.subplots()` in Matplotlib/pyplot/python Modify the legend of pandas bar plot Format y axis as percent Simple line plots using seaborn Plot bar graph from Pandas DataFrame Plotting multiple lines, in different colors, with pandas dataframe Plotting in a non-blocking way with Matplotlib What does the error "arguments imply differing number of rows: x, y" mean? matplotlib get ylim values

Examples related to legend

Edit seaborn legend Remove legend ggplot 2.2 Reduce size of legend area in barplot Matplotlib scatter plot legend matplotlib: colorbars and its text labels Add a common Legend for combined ggplots Is there a way to change the spacing between legend items in ggplot2? Add legend to ggplot2 line plot plot legends without border and with white background Moving matplotlib legend outside of the axis makes it cutoff by the figure box