data:The Diamonds dataset in Ggplot2, using a random sample to fetch 1000 samples, the code is as follows:
> Library (GGPLOT2)
> Data ("Diamonds")
> Head (Diamonds)
> set.seed (1234)
> Small <-diamonds[sample (Nrow (Diamonds), 1000),]
Histogram
> Ggplot (Small) +geom_histogram (Aes (X=price), fill= "Cornflowerblue", colour= "Black", binwidth= 1000)
Stacked Histogram
Use the "Cut" column in the data (divided into 5 grades, used to differentiate the quality of the diamond) to make a stacked histogram as follows:
>ggplot (small) +geom_histogram (Aes (X=price), fill= "Cornflowerblue", colour= "Black", binwidth= 1000)
Box Line diagram
> Ggplot (Small) +geom_boxplot (Aes (X=cut,y=price), fill= "Cornflowerblue", colour= "Black")
Bar chart
>ggplot (small) +geom_bar (Aes (x=clarity), fill= "Cornflowerblue", colour= "Black")
Pie chart
>ggplot (small) +geom_bar (Aes (X=factor (1), fill=cut), width=1) +coord_polar (theta= "Y")
R Language Learning notes--drawing with Ggplot2