본문 바로가기
반응형

분류 전체보기123

The way to color bar graph - colour,fill,scale_fill_brewer,scale_fill_manual 1. geom_bar(colour=, fill=) colour= color the border of graph fill= fill the graph > ggplot(data=mpg,aes(x=cyl))+geom_bar()> ggplot(data=mpg,aes(x=cyl))+geom_bar(fill="blue")> ggplot(data=mpg,aes(x=cyl))+geom_bar(fill="white",colour="blue") 2. fill graphs separately by a variable. -geom_bar(x=, y=, fill= 'a variable')-geom_bar()+scale_fill_brewer-geom_bar()+scale_fill_manual >library(ggplot2) >l.. 2020. 8. 14.
(R) The way to make bar_graph having both x and y/geom_bar(stat="identity) When using bar graph, you cannot have both variable x and y in the graph. > ggplot(data=msleep2,aes(x=vore,y=mean_sleep))+geom_bar()Error: stat_count() can only have an x or y aesthetic. Generally, y-axis of bar graph automatically becomes 'counts'. You can make the bar_graph having variables for x-axis and y-axis by using geom_bar(stat="identity) variable x and count - geom_bar() variable x and.. 2020. 8. 13.
(R)ways to draw curve (function) -curve(), ggplot() 1. exponential distribution > curve(dexp(x,rate=2),from=0,to=6) >ggplot(data.frame(x=c(0,6)),aes(x=x))+stat_function(fun=dexp,args=list(rate=2)) 2. Normal distribution > curve(dnorm(x,mean=5,sd=1),from=-10,to=10) >ggplot(data.frame(x=c(-10,10)),aes(x=x))+stat_function(fun=dnorm,args=list(mean=5,sd=1)) 3. T distribution >curve(dt(x,df=3),from=0,to=10) >ggplot(data.frame(x=c(0,10)),aes(x=x))+stat_.. 2020. 8. 13.
ways to make boxplot (one variable, two variables in x-axis) / boxplot(),qplot(),ggplot() When making boxplots, there is the critical point you have to keep in mind. Boxplots will be successfully made when the variable of x-axis is not numeric data. So variable in x-axis should be factor type of character type when making boxplots. > str(msleep$vore) chr [1:83] "carni" "omni" "herbi" "omni" "herbi" "herbi" ... > table(msleep$vore) carni herbi insecti omni 19 32 5 20 The variable 'vor.. 2020. 8. 11.
반응형