0

I am very new to R and I am trying to create a barplot with my infiltration on the y axis and burn on the x axis comparing the grazing treatment (example of the data set is below)

Infiltration    Grazing Burn
3301.145496 G   S
8165.771889 U   S
9937.833576 G   L
11576.5892  U   L
32739.07643 G   N
25923.84328 U   N
25942.3     G   C  

So far I have produced the code so that it reads the table

   #reads the basic data in
   ana<-read.table("D:\\Dave.txt",head=T)
   attach(ana)
   head(ana)
   dim(ana)

However I do not understand how to write the code to produce a barplot.

I have attached an image of how I produced the graph on excel excel graph

Also I do not have the ggplot, how do I format it as "barplot(....."

1
  • Also I do not know how to format the data I added add the top into table - I am aware it reads terribly Commented Feb 8, 2018 at 15:59

2 Answers 2

1

With the sample dataset available, an example could be:

barplot(as.matrix(mtcars[,10:11]), beside = TRUE)

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

what does the [10:11] mean?
This is matrix notation. [,10:11] means columns 10 to 11 ([10:11,] would mean rows 10 to 11. with the mtcars dataset this means mtcars$gear and mtcars$carb
I still do not understand how to write this in the format of my own data
0

With your dataset and assuming 'ana$burn' is coded as a factor:

barplot(xtabs(ana$Infiltration ~ ana$Burn + ana$Grazing),beside = TRUE)

The beside = TRUE gives your barplot side by side, if you want to stack, put beside = FALSE (just look at the two, see what you prefer).

If 'ana$Burn' and 'ana$Grazing' not coded as factor, you need to add this before:

ana$Burn = as.factor(ana$Burn)
ana$Grazing = as.factor(ana$Grazing)

2 Comments

thank you. This works however only plots the burn, how do I go about adding the grazing treatment on the barplot ?
I edited my answer. See if it works for you and accept it if that's the case

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.