Plotting bar chart ,data is imported via CSV File

I m new to Rstudio When I tried to plot a barchart to show the Name vs Grade, I m getting the error as Preformatted text

Blockquote
|Naame|Grade|
|---|---|
|A|24|
|B|20|
|C|30|
|D|50|
|E|50|
|F|60|
|G|70|
|H|80|
|I|90|

Data Set

Check2 <- read.csv("F:/MYFiles/Semester2/Final Data/Check2.csv")
View(Check2)

summary(Check2)
Naame Grade
A :1 Min. :20.00
B :1 1st Qu.:30.00
C :1 Median :50.00
D :1 Mean :52.67
E :1 3rd Qu.:70.00
F :1 Max. :90.00
(Other):3

barplot(Check2, main="Grade",

  •     xlab="Name")
    

Error in barplot.default(Check2, main = "Grade", xlab = "Name") :
'height' must be a vector or a matrix

barplot(Grade,names.arg=Naame,xlab="Name",ylab="Grade",col="blue",

  •     main="Marks chart",border="red")
    

Error in barplot(Grade, names.arg = Naame, xlab = "Name", ylab = "Grade", :
object 'Grade' not found

barplot(Check2,names.arg=Naame,xlab="Name",ylab="Grade",col="blue",

  •     main="Marks chart",border="red")
    

Error in barplot.default(Check2, names.arg = Naame, xlab = "Name", ylab = "Grade", :
object 'Naame' not found

Look at the documentation and examples of barplot (help pane in rstudio or ?barplot. You'll see how to work with this function. You cannot provide a data.frame - you must provide a vector with bar height or a matrix. Look at the example.

If you are new to R and want to explore data with graphics, I would advice to use ggplot2. Look at this introduction :

geom_col would be the the function you need to get a barplot, providinx x but also y as you know the height. Something like

library(ggplo2)
ggplot(Check2, aes(x = Name, y = Grade)) + 
    geom_col()

Look also at ?geom_col

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.