A very simple histogram with R?

I start very hard with programming R. I use RStudio for the exam, and I have to graphically present the results of some calculations in the data set. I have a structure like this:

enter image description here

and what I was going to do is make some histograms with three average values ​​for each row, as well as for the average and the cropped average.

First question: Is this the right way to present this kind of data graphically? Or is there some better plot.

Second question: Can someone give me a code to draw a graph on x avis 3 lines ("Lobby", "R and D", "ROE") and on the y axis - a scale of values ​​that includes the results to have histograms representing the differences in investment in lobbing, r and d and caviar obtained.

Hope I was clear enough, if I did not indicate something important, ask me.

0
source share
2 answers

It looks like you want to do the following. With your data in a csv call bar.csvhaving this format:

Dept    Mean    Median  Trimmed_Mean
Lobby   0.008   0.0018  0.0058
R & D   6.25    3.2     4.78
ROE     19.08   16.66   16.276

You can use library(ggplot2)both the library(reshape)commands given here.

dat.m<-read.csv("bar.csv")
dat.m<-melt(dat.m,id.vars="Dept")

ggplot(dat.m, aes(x = Dept, y = value,fill=variable)) + geom_bar(stat='identity')+
facet_wrap(~ Dept, ncol = 3,scales="free_y") #facet wrapped

ggplot(dat.m, aes(x = Dept, y = value,fill=variable)) + geom_bar(stat='identity') 
#stacked bar

To display the graphs below:

stacked facetstacked bar

zhaoy, () - . , library(ggplot2) boxplot, ( spray ggplot2):

library(ggplot2)
p<-qplot(spray,count,data=InsectSprays,geom='boxplot')
p<-p+stat_summary(fun.y=mean,shape=1,col='red',geom='point')
print(p)

boxplot, , :

boxplot(count ~ spray, data = InsectSprays, col = "lightgray")
means <- tapply(InsectSprays$count,InsectSprays$spray,mean)
points(means,col="red",pch=18)
+1

1: - . // 3 row.name, . , // , 3- .

2: 3 row.name, , . , , . . r-bloggers.com/box-plot-with-r-tutorial .

0

Source: https://habr.com/ru/post/1017323/


All Articles