본문 바로가기
반응형

R71

(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.
Ways to draw histogram, adjust the width of boxes/ hist(),ggplot(),qplot() I will make a histogram from data 'airqulity' which is built in the ggplot2 package. histogram is a graphical display of distribution of data which consists of nonoverlapping bins. Generally, y-axis of histograms which is the height of each bin in the histogram is proportional to frequencies of the number of cases of the unit of the variable in x-axis. The graphs below represents the distributio.. 2020. 8. 11.
반응형