본문 바로가기
반응형

R71

(R) Ways to make Bar graph (continuous variable --> Discrete variable)/qplot, ggplot,barplot continuous variable _x discrete variable_x > table(mpg$cyl) 4 5 6 8 81 4 79 70 >barplot(table(mpg$cyl)) > ggplot(data=mpg,aes(x=cyl))+geom_bar() > qplot(mpg$cyl,binwidth=0.5) When the variable x is a numeric value, the variable is regarded as continuous variable using ggplot()-geom_bar(),geom_col() and the graph becomes containing the vacant element. (ex) cyl=7 above You can make the variable di.. 2020. 8. 11.
(R) two lines in a graph, lines and points in a graph. > plot(women$height,women$weight,type="l") > ggplot(data=women,aes(x=height,y=weight))+geom_line() > qplot(data=women,height,weight,geom="line") > plot(women$height,women$weight,type="l")> points(women$height,women$weight)> ggplot(data=women,aes(x=height,y=weight))+geom_line()+geom_point()> qplot(data=women,height,weight,geom=c("line","point")) > ggplot(data=women,aes(x=height,y=weight))+geom_li.. 2020. 8. 10.
(R) list colors of columns in order / character type to factor type list colors of columns in order. *character type to factor type* >library(ggplot2) >library(dplyr)> Ozone_temp_rate%count(Ozone_rank,temp_rank)%>%group_by(Ozone_rank)%>%mutate(per=n/sum(n)*100)> ggplot(data=Ozone_temp_rate,aes(x=Ozone_rank,y=per,fill=temp_rank))+geom_col()> class(Ozone_temp_rate$temp_rank) [1] "character"> levels(Ozone_temp_rate$temp_rank) ------------------no levels because the.. 2020. 7. 30.
(R) Reorder columns in any orders / scale_x_discrete() scale_x_discrete() >library(ggplot2) ------------for 'airquality' data >library(dplyr)> summary(airquality$Ozone) Min. 1st Qu. Median Mean 3rd Qu. Max. NA's 1.00 18.00 31.50 42.13 63.25 168.00 37 > summary(airquality$Temp) Min. 1st Qu. Median Mean 3rd Qu. Max. 56.00 72.00 79.00 77.88 85.00 97.00 > airquality_%filter(!is.na(Ozone))%>%mutate(Ozone_rank=ifelse(Ozone Ozone_temp%group_by(Ozone_rank)%.. 2020. 7. 30.
반응형