options(repos = list(CRAN="http://cran.rstudio.com/"))
install.packages("tidyverse", repos = "http://cran.us.r-project.org")
## package 'tidyverse' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\User\AppData\Local\Temp\RtmpO2ul18\downloaded_packages
library(tidyverse)
library(readr)
winequality_red <- read_delim("C:/Users/User/Downloads/winequality-red.csv",
delim = ";", escape_double = FALSE, trim_ws = TRUE)
View(winequality_red)
w<-winequality_red
dim(w)
## [1] 1599 12
nrow(w)
## [1] 1599
ncol(w)
## [1] 12
str(w)
## spc_tbl_ [1,599 × 12] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ fixed acidity : num [1:1599] 7.4 7.8 7.8 11.2 7.4 7.4 7.9 7.3 7.8 7.5 ...
## $ volatile acidity : num [1:1599] 0.7 0.88 0.76 0.28 0.7 0.66 0.6 0.65 0.58 0.5 ...
## $ citric acid : num [1:1599] 0 0 0.04 0.56 0 0 0.06 0 0.02 0.36 ...
## $ residual sugar : num [1:1599] 1.9 2.6 2.3 1.9 1.9 1.8 1.6 1.2 2 6.1 ...
## $ chlorides : num [1:1599] 0.076 0.098 0.092 0.075 0.076 0.075 0.069 0.065 0.073 0.071 ...
## $ free sulfur dioxide : num [1:1599] 11 25 15 17 11 13 15 15 9 17 ...
## $ total sulfur dioxide: num [1:1599] 34 67 54 60 34 40 59 21 18 102 ...
## $ density : num [1:1599] 0.998 0.997 0.997 0.998 0.998 ...
## $ pH : num [1:1599] 3.51 3.2 3.26 3.16 3.51 3.51 3.3 3.39 3.36 3.35 ...
## $ sulphates : num [1:1599] 0.56 0.68 0.65 0.58 0.56 0.56 0.46 0.47 0.57 0.8 ...
## $ alcohol : num [1:1599] 9.4 9.8 9.8 9.8 9.4 9.4 9.4 10 9.5 10.5 ...
## $ quality : num [1:1599] 5 5 5 6 5 5 5 7 7 5 ...
## - attr(*, "spec")=
## .. cols(
## .. `fixed acidity` = col_double(),
## .. `volatile acidity` = col_double(),
## .. `citric acid` = col_double(),
## .. `residual sugar` = col_double(),
## .. chlorides = col_double(),
## .. `free sulfur dioxide` = col_double(),
## .. `total sulfur dioxide` = col_double(),
## .. density = col_double(),
## .. pH = col_double(),
## .. sulphates = col_double(),
## .. alcohol = col_double(),
## .. quality = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
class(w$`fixed acidity`)
## [1] "numeric"
class(w$`volatile acidity`)
## [1] "numeric"
class(w$`citric acid`)
## [1] "numeric"
class(w$`residual sugar`)
## [1] "numeric"
class(w$chlorides)
## [1] "numeric"
install.packages("ggplot2")
library(ggplot2)
library(RColorBrewer)
#variable ph
ph<-as.data.frame(table(w$pH))
ggplot(data=ph, aes(x=Var1, y=Freq,fill=Var1))+geom_bar(stat="identity")
You can also embed plots, for example:
install.packages("BSDA")
## package 'BSDA' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\User\AppData\Local\Temp\RtmpO2ul18\downloaded_packages
library(BSDA)
data("Sports")
Sports_table<-as.data.frame(table(Sports$sport))
ggplot(data=Sports_table, aes(x=Var1, y=Freq,fill=Var1)) +
geom_bar(stat="identity",color="white")+
theme_light()+
labs(title = "Barplot for Favorite Sports",y="Frequency",x="Sports")+
ggeasy::easy_center_title()+
geom_text(aes(label=Freq),position =position_stack(0.5),color="white")+
scale_fill_manual(values = c('#7fc97f','#beaed4','#fdc086','#ff3f99'))