Search code examples
rggplot2data-visualizationdistribution

What is the best plot to show a distribution in R?


I'm looking to plot the distribution of age across the different trees in the locality data.

I did the following but the graph isn't representative :

ggplot(tree_data, aes(x = Age.Life, fill = Tree)) + 
geom_density(alpha=.5) + 
scale_fill_brewer(palette="Set1")

Solution

  • Try the geom_boxplot() distribution:

    ggplot(iris, aes(x = Petal.Length, fill=Species)) + 
      geom_boxplot() + 
      scale_fill_brewer(palette="Set1")
    

    enter image description here

    Or geom_histogram() As @akrun suggests. I've added combined with facet_grid().

    ggplot(iris, aes(x = Petal.Length, y=Species, fill=Species)) + 
      geom_histogram() + 
      scale_fill_brewer(palette="Set1")+
      facet_grid("Species")
    

    enter image description here

    And the popular geom_violin() plot

    ggplot(iris, aes(x = Petal.Length, y=Species, fill=Species)) + 
      geom_violin() + 
      scale_fill_brewer(palette="Set1")
    

    enter image description here