Barplot; Need help to solve this code

Need help to solve this code

bionew1 <- c(a,b,c,d,e,f,g,h,i,j,k)
names(bionew1) <- c("Beetle",
"Bird",
"Butterfly",
"Dragonfly",
"Flowering.Plants",
"Fungus",
"Hymenopteran",
"Lichen",
"Liverwort",
"Mammal",
"Mollusc")

barplot(bionew1)

#error message I get is:

barplot(bionew1)
Error: object 'bionew1' not found

Are you sure thats the first error and not the last/most recent ?
You should address earlier errors before later ones, as issues naturally propogate down scripts.
where you make bionew1 in the first line are you sure to have every name you reference be bound to a value ? does it run without error

@nirgrahamuk Yes I believe this is the last error, but let me post the entire code for you to see

library(dplyr)

new1 <- read.csv("C:/Users/Administrator/Documents/R_Language/edidiv.csv")

head(new1$taxonGroup)
class(new1$taxonGroup)
new1$taxonGroup <- as.factor(new1$taxonGroup)
class(new1$taxonGroup)
dim(new1)
summary(new1)
summary(new1$taxonName)

Beetle <- filter(new1, taxonGroup == "Beetle")

Bird <- filter(new1, taxonGroup == "Bird")

a <- length(unique(Beetle$taxonName))
b <- length(unique(Bird$taxonName))

bionew1 <- c(a,b,c,d,e,f,g,h,i,j,k)
names(bionew1) <- c("Beetle",
"Bird",
"Butterfly",
"Dragonfly",
"Flowering.Plants",
"Fungus",
"Hymenopteran",
"Lichen",
"Liverwort",
"Mammal",
"Mollusc")

barplot(bionew1)

based on what you shared, you have not provided d,e,f,g,h,i,j,k so bionew1 <- c(...) would be expected to fail.

okay, any solution for that, please?

it looks like you (or someone you received code from ) , took the length of unique taxonNames under Bird and Beetle taxon Groups out of new1 . but only those two and not the rest.

perhaps the pattern needs to be continued and the same done for the rest ...

I took the code from this link, where I am learning how to code in R (Getting started with R and RStudio)

everything from the beginning was working until the last part

it was left as an exercise for the reader. the text says as much

You need to do these steps for ALL of the taxa in the data, here we have given examples for the first two

This doesn't look to me like a great way to get started with R, I would recommend swirl, and R for Data Science (2e) (hadley.nz)

1 Like

Totally agree. and R for Data Science is great.... but for an absolute beginner I'd recommend:

Hands On Programming in R

Thank you so much for your help and advice

This will not work. You cannot create a character vector that way. You can do this

bionew1 <- c("a", "b", "c", "d", "e" , "f", "g", "h" , "i", "j", "k")

It still will not work because a barplot needs numeric values not character values.

Something like this will work


bionew1 <- c(1:11)
names(bionew1) <- c("Beetle",   "Bird", "Butterfly", "Dragonfly", "Flowering.Plants",
"Fungus", "Hymenopteran", "Lichen", "Liverwort", "Mammal", "Mollusc")

barplot(bionew1)

@jrkrideau thank you so much for your efforts and thank you all for your ideas and sharing. I really appreciate it. Thank you.

This topic was automatically closed 7 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.