How to edit a ggplot

Is there a way to make the legend smaller and the graph larger? I keep getting an extremely large legend with a small graph and I need it to be the opposite.

Here is my code:
ggplot(Metro, aes(x=MedianSalePrice, fill=Region)) +geom_histogram(binwidth = 50)+labs(x="MedianSalePrice")

Here is what I get:

Here is a small sample of the dataset

Region PeriodEnd MedianSalePrice HomesSold NewListings Inventory
National March 2014 214500 8 5 38
National June 2014 264000 7 8 35
National July 2014 225550 4 11 39
National August 2014 246500 8 5 31
National October 2014 232500 6 5 34
National November 2014 207500 6 7 33
National January 2015 277500 4 10 34
National February 2015 234950 6 3 35
National April 2015 216300 7 4 29
National July 2015 271600 10 8 36
National August 2015 176500 6 12 41
National September 2015 165000 5 8 42
National October 2015 95339 2 7 42
National November 2015 235000 5 8 37
National December 2015 225000 13 2 28
National February 2016 182000 2 11 32
National March 2016 200400 4 10 34
National April 2016 222500 14 8 28
National May 2016 246000 7 9 29
National June 2016 256000 11 19 33
National July 2016 275000 7 7 34
National August 2016 269900 5 9 31
National October 2016 222500 9 3 26
National January 2017 245000 7 12 26
National February 2017 245100 7 14 34
National March 2017 257450 6 12 32
National April 2017 266750 14 8 30
National May 2017 278900 7 9 30
National June 2017 250000 7 6 30
National July 2017 283500 7 7 30
National January 2018 240125 4 4 21
National February 2018 258000 3 6 19
National June 2018 257500 15 5 18
National July 2018 258000 9 10 23
National October 2018 277475 10 9 30
National December 2018 280350 6 5 20
National January 2019 285750 4 10 20
National March 2019 268250 6 9 24
National April 2019 272000 9 15 31
National July 2019 283000 9 10 32
National August 2019 278500 5 4 31
National September 2019 265000 9 3 24
National October 2019 270000 11 7 18
National December 2019 234000 4 2 12
National July 2020 279900 11 10 12
National September 2016 93000 10 8 41
National December 2016 128000 10 11 46
National January 2017 126250 4 12 49
National February 2017 97000 7 13 48
National March 2017 131000 6 11 49
National May 2017 107500 10 7 42
National June 2017 123000 7 12 46
National July 2017 95000 5 5 42
National August 2017 122125 2 9 47
National November 2017 147000 7 13 44
National December 2017 140000 9 11 48
National January 2018 147000 8 17 51
National February 2018 115000 7 15 54
National March 2018 128750 12 15 53
National April 2018 152000 3 12 55
National May 2018 138000 8 19 66
National June 2018 146250 4 5 65
National July 2018 155000 3 9 62
National August 2018 133500 9 14 57
National September 2018 115000 11 12 57
National December 2018 112750 10 12 49
National January 2019 140000 8 18 53
National February 2019 124000 16 12 55
National March 2019 140750 8 13 54
National April 2019 135000 13 8 46
National May 2019 147950 8 12 40
National June 2019 147000 10 18 47
National July 2019 145150 10 12 43
National August 2019 140800 17 11 42
National September 2019 144451 10 14 43
National October 2019 139000 13 15 46
National November 2019 149900 5 11 45
National December 2019 168000 9 18 52
National January 2020 140350 16 22 59
National February 2020 163400 13 21 55
National March 2020 160000 20 13 51
National April 2020 169000 7 15 55
National May 2020 163000 9 19 53
National June 2020 161500 18 13 48
National July 2020 174000 9 18 52
National August 2020 139000 13 15 46
National September 2020 155500 22 13 36
National October 2020 142000 17 15 36
National November 2020 154000 13 18 44
National December 2020 137400 10 23 48
National January 2021 145000 8 19 47
National February 2021 139500 12 23 49

What are you trying to do with this data? It looks like you have 64 categories of data. How much data overall if your small sample has 92 data points?

I just cannot see that a histogram of all those categories is going to be interpretable in a simple histogram. It might make sense to facet by Region but there likely are better ways to graph the data.

Re the sample data you supplied, it is appreciated but a better way to supply it to use the dput() function.
See ?dput. If you have a very large data set then something like head(dput(myfile), 100) will usually supply enough data for us to work with. However in this case we probably need a random sample rather than data from just one Region.

As a very simple step---not that will cure your problem---just get rid of the legend and see what you get

ggplot(Metro, aes(x=MedianSalePrice, fill=Region)) +geom_histogram(binwidth = 50)+
  theme(legend.position = "none")
2 Likes

Seems a geo-facet might help but first what questions or comparisons you are after?

Thank you for your assistance. I have 6000 data points; I did not post them. However, I changed the font and put the graph in a second window that seemed to work.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.