0

I'd like to adjust the area of the graph to the values shown. I do not want to have the white are of the graph above 1 and below 0

this is my code

percentage <- ggplot(mabar, aes(x = as.numeric(Year), y = value, fill = variable)) +
  geom_area(position = "fill", colour = "black", size = .2, alpha = .4) +
  scale_fill_brewer(palette = "Blues") +
  #scale_fill_viridis_d() +
  labs(x = "Year", y = "Percentage of total value of M&A deals")+
  theme(legend.position = "bottom")+ 
  theme_ipsum()

here the data I use:

dput(mabar)
structure(list(Year = c(1985, 1986, 1987, 1988, 1989, 1990, 1991, 
1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 
2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 
2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 1985, 1986, 1987, 
1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 
2021), variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L), levels = c("valueROW", "ValueUS"), class = "factor"), 
    value = c(41.36, 81.46, 132.83, 190.95, 291.91, 285.84, 220.01, 
    214.87, 198.39, 209.3, 372.42, 466.61, 707.78, 861.59, 1977.82, 
    1657.19, 855.42, 721.46, 742.14, 1138.58, 1451.9, 2179.11, 
    2952.94, 1859.91, 1309.39, 1768.2, 1420.96, 1537.35, 1321.21, 
    1806.2, 2361.61, 1861.23, 2015.46, 1461.753, 1482.536, 1691.57, 
    2311, 305.64, 353.54, 373.17, 586.05, 466.09, 254.16, 176.99, 
    185.13, 317.61, 414.7, 666.58, 750.39, 1116.22, 1816.41, 
    2138.18, 1965.81, 1010.58, 520.54, 668.86, 1006.42, 1342.1, 
    1843.89, 1967.06, 1215.09, 877.61, 981.8, 1247.04, 995.65, 
    1214.79, 2153.8, 2417.39, 1784.77, 1761.54, 1931.81, 1887.57, 
    1125.82, 2587)), row.names = c(NA, -74L), class = "data.frame")
stefan
  • 90,330
  • 6
  • 25
  • 51
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 28 '22 at 16:38
  • Yes, sorry. I added the data. – Ayoze Alfageme Nov 28 '22 at 16:45
  • 1
    Try `+ scale_y_continuous(expand = c(0, 0))` – stefan Nov 28 '22 at 16:49
  • many thanks! that works. I have a extra issue I use the following code with the same data and the legend keep showing to the right of the graph. Any clue why? Thanks in advance: ggplot(mabar, aes(x = Year, y = value, fill = variable)) + geom_area(position = "fill", colour = "black", size = .2, alpha = .4) + scale_fill_brewer(palette = "Blues") + scale_y_continuous( expand = c(0,0))+ #scale_fill_viridis_d() + labs(x = NULL, y = "Percentage of total value of M&A deals")+ labs(fill = NULL, color = NULL)+ theme(legend.position = "bottom") + theme_ipsum() – Ayoze Alfageme Nov 28 '22 at 16:52
  • 1
    Do `theme_ipsum() + theme(legend.position = "bottom")`, i.e. always set the the theme first, then do your adjustments. Otherwise the legend position is overwritten by the default of `theme_ipsum` which is probably "right". – stefan Nov 28 '22 at 17:19

0 Answers0