Error-Series: Just to Plot a Single Graph–How Much Errors you can make

Learning is fun; Sometime its a pain too; So I thought, I will post all the trial and errors done by me in a error series posts. Though, when you finally come up with a plot, It feels good.

Once I was trying my best to plot a stack bar for microbiological data. and the codes and errors goes like this.  (This is that plot – that came after hundreds of errors; though the data frame was as simple as it could be)

Domain  Rice  Tea  Soil

Archaea value value value

image

> Domain.Abundance <- read.csv(“C:/Users/sdas4/Desktop/Host Dependency Paper/Domain Abundance.csv”)

> DM <- Domain.Abundance

> DM %>% ggplot(aes(y= “domain”)) + geom_bar()

Error: stat_count() must not be used with a y aesthetic.

> DM %>% ggplot(domain, aes()) + geom_bar()

Error in ggplot.default(., domain, aes()) : object ‘domain’ not found

> DM %>% ggplot(aes(domain)) + geom_bar()

> DM %>% ggplot(aes(x=”environment”)) + geom_bar(aes((color))

+ DM %>% ggplot(aes(x=”environment”)) + geom_bar(aes((color))

Error: unexpected symbol in:

“DM %>% ggplot(aes(x=”environment”)) + geom_bar(aes((color))

DM”

> DM %>% ggplot(aes(x=”environment”)) + geom_bar(aes((color))

+ DM %>% ggplot(aes(x=”environment”)) + geom_bar(aes((color)))

Error: unexpected symbol in:

“DM %>% ggplot(aes(x=”environment”)) + geom_bar(aes((color))

DM”

> DM %>% ggplot(aes(x=”environment”)) + geom_bar(aes(color = domain))

> DM %>% ggplot(aes(x=”environment”)) + geom_bar(position = “stack”)

> DM %>% ggplot(aes(x=domain)) + geom_bar(position = “stack”)

> DM %>% ggplot(aes(x=domain)) + geom_bar(position = “stack”, aes(color = “Environment”))

> DM %>% ggplot(aes(x=domain)) + geom_bar(position = “stack”, aes(color = “Environment”))

Error in FUN(X[[i]], …) : object ‘domain’ not found

> DM %>% ggplot(aes(Environment)) + geom_bar(position = “stack”, aes(color = “Environment”))

> DM %>% ggplot(aes(Environment)) + geom_bar(position = “stack”, aes())

> DM %>% ggplot(aes(x = “Environment”)) + geom_bar(aes(fill = c(“Archaea”, “Bacteria”, “Eukaryota”, “Viruses” “other.sequences”))

Error: unexpected string constant in “DM %>% ggplot(aes(x = “Environment”)) + geom_bar(aes(fill = c(“Archaea”, “Bacteria”, “Eukaryota”, “Viruses” “other.sequences””

> )))

Error: unexpected ‘)’ in “)”

> DM %>% ggplot(aes(Environment)) + geom_bar(aes(fill = c(“Archaea”, “Bacteria”, “Eukaryota”, “Viruses” “other.sequences”)))

Error: unexpected string constant in “DM %>% ggplot(aes(Environment)) + geom_bar(aes(fill = c(“Archaea”, “Bacteria”, “Eukaryota”, “Viruses” “other.sequences“”

> DM <- Domain.Abundance

> DM %>% ggplot(aes(Environment)) + geom_bar(aes(fill = c(“Archaea”, “Bacteria”, “Eukaryota”, “Viruses” “other.sequences”)))

Error: unexpected string constant in “DM %>% ggplot(aes(Environment)) + geom_bar(aes(fill = c(“Archaea”, “Bacteria”, “Eukaryota”, “Viruses” “other.sequences””

> DM %>% ggplot(aes(Environment)) + geom_bar(aes(color = c(“Archaea”, “Bacteria”, “Eukaryota”, “Viruses” “other.sequences”)))

Error: unexpected string constant in “DM %>% ggplot(aes(Environment)) + geom_bar(aes(color = c(“Archaea”, “Bacteria”, “Eukaryota”, “Viruses” “other.sequences””

> DM %>% ggplot(aes(Environment)) + geom_bar(aes(color = c(“Archaea”, “Bacteria”, “Eukaryota”, “Viruses”, “other.sequences”)))

Error: Aesthetics must be either length 1 or the same as the data (3): colour

> DM %>% ggplot(Environment, aes()) + geom_bar(stat = “identity”, position = “fill”)

Error in ggplot.default(., Environment, aes()) :

object ‘Environment’ not found

> DM %>% ggplot(“Environment”, aes()) + geom_bar(stat = “identity”, position = “fill”)

Error: Mapping should be created with `aes() or `aes_()`.

> install.packages(“reshape2”)

> library(reshape2)

Warning message:

package ‘reshape2’ was built under R version 3.5.2

> mytable <- melt(DM, id.vars = c(“Environment”), value.name = “proportion”)

> View(mytable)

> mytable %>% ggplot() + geom_bar(aes(x = “Environment” y = proportion, fill = variable, stat = “identity”))

Error: unexpected symbol in “mytable %>% ggplot() + geom_bar(aes(x = “Environment” y”

> mytable %>% ggplot() + geom_bar(aes(x = “Environment”, y = proportion, fill = variable, stat = “identity”))

Warning: Ignoring unknown aesthetics: stat

Error: stat_count() must not be used with a y aesthetic.

> ggplot() + geom_bar(aes(mytable$Environment,mytable$proportion, fill = mytable$variable, data = mytable, stat = “identity”))

Warning: Ignoring unknown aesthetics: data, stat

Don’t know how to automatically pick scale for object of type data.frame. Defaulting to continuous.

Error: Aesthetics must be either length 1 or the same as the data (15): data

> View(mytable)

> ggplot(mytable, aes(x = Environment, y= proportion, fill= variable)) + geom_bar()

Error: stat_count() must not be used with a y aesthetic.

> ggplot(mytable, aes(x = Environment, y= proportion, fill= variable)) + geom_bar(aes(stat = “identity”))

Warning: Ignoring unknown aesthetics: stat

Error: stat_count() must not be used with a y aesthetic.

> ggplot(mytable, aes(Environment, proportion, fill= variable)) + geom_bar(aes(stat = “identity”))

Warning: Ignoring unknown aesthetics: stat

Error: stat_count() must not be used with a y aesthetic.

> ggplot(mytable, aes(x = “Environment”, y = “proportion”)) + geom_bar(aes(stat = “identity”))

Warning: Ignoring unknown aesthetics: stat

Error: stat_count() must not be used with a y aesthetic.

> ggplot(mytable, aes(x = “Environment”, y = “proportion”)) + geom_bar(aes(stat = “identity”, fill = variable))

Warning: Ignoring unknown aesthetics: stat

Error: stat_count() must not be used with a y aesthetic.

> P <- ggplot(mytable, aes())

> P + geom_bar()

Error: stat_count requires the following missing aesthetics: x

> P + geom_bar(aes(x = Environment))

> P + geom_bar(aes(x = Environment, fill = variable))

> P + geom_bar(aes(x = Environment, fill = variable, ylab = “abundance”))

Warning: Ignoring unknown aesthetics: ylab

Error: stat_count() must not be used with a y aesthetic.

> P + geom_bar(aes(x = Environment, fill = variable, ylab = abundance))

Warning: Ignoring unknown aesthetics: ylab

Error in FUN(X[[i]], …) : object ‘abundance’ not found

> P + geom_bar(aes(x = Environment, fill = variable))

> myTable <- prop.table(mytable, 1)

Error in margin.table(x, margin) : ‘x’ is not an array

> myTable <- prop.table(mytable)

Error in FUN(X[[i]], …) :

only defined on a data frame with all numeric variables

> myTable <- prop.table(mytable, 3)

Error in margin.table(x, margin) : ‘x’ is not an array

> myTable <- prop.table(mytable)

Error in FUN(X[[i]], …) :

only defined on a data frame with all numeric variables

> myTable <- prop.table(mytable$proportion)

> View(myTable)

> myTable <- prop.table(mytable$Environment, mytable$proportion)

Error in margin.table(x, margin) : ‘x’ is not an array

> mytable %>% mutate(perentage = proportion/mean(proportion)*100)

Environment variable proportion perentage

1 Tea Archaea 6 3.937542e-02

2 Rice Archaea 0 0.000000e+00

3 Soil Archaea 1622 1.064449e+01

> P + geom_bar(aes(x = Environment, y= percentage, fill = variable))

Error in FUN(X[[i]], …) : object ‘percentage’ not found

> mytable %>% mutate(perentage = proportion/mean(proportion)*100)

Environment variable proportion perentage

1 Tea Archaea 6 3.937542e-02

2 Rice Archaea 0 0.000000e+00

3 Soil Archaea 1622 1.064449e+01

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)

Environment variable proportion percentage

1 Tea Archaea 6 3.937542e-02

2 Rice Archaea 0 0.000000e+00

3 Soil Archaea 1622 1.064449e+01

> P + geom_bar(aes(x = Environment, y= percentage, fill = variable))

Error in FUN(X[[i]], …) : object ‘percentage’ not found

> P + geom_bar(aes(x = Environment, y= percentage, fill = variable))

Error in FUN(X[[i]], …) : object ‘percentage’ not found

> P + geom_bar(aes(x = Environment, y= “percentage”, fill = variable))

Error: stat_count() must not be used with a y aesthetic.

> P <- ggplot(mytable, aes(Environment, percentage))

> P + geom_bar(aesfill = variable))

Error: unexpected ‘)’ in “P + geom_bar(aesfill = variable))”

> P + geom_bar(aes(fill = variable))

Error in FUN(X[[i]], …) : object ‘percentage’ not found

> View(mytable)

> mytable %>% mutate(percentage = proportion/mean(proportion)*100) %>% ggplot(aes(Environment, percentage)) + geom_bar(aes(fill = variable))

Error: stat_count() must not be used with a y aesthetic.

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)

Environment variable proportion percentage

1 Tea Archaea 6 3.937542e-02

2 Rice Archaea 0 0.000000e+00

3 Soil Archaea 1622 1.064449e+01

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(Environment, percentage, color = variable)) + geom_bar()

Error: stat_count() must not be used with a y aesthetic.

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(Environment, color = variable)) + geom_bar()

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot() + geom_bar(aes(x = “Environment”, y = “percentage”))

Error: stat_count() must not be used with a y aesthetic.

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=percentage)) + geom_bar(stat = “identity”, position = “stack”)

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=percentage, color = variable)) + geom_bar(stat = “identity”, position = “stack”)

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=percentage, fill = variable)) + geom_bar(stat = “identity”, position = “stack”)

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=percentage, fill = variable, ylab(percetage of abundance))) + geom_bar(stat = “identity”, position = “stack”)

Error: unexpected symbol in “mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=percentage, fill = variable, ylab(percetage of”

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=percentage, fill = variable)) + geom_bar(stat = “identity”, position = “stack”) + labs(y= “Percentage of Abundance”)

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=proportion, fill = variable)) + geom_bar(stat = “identity”, position = “stack”) + labs(y= “Percentage of Abundance”)

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=proportion, fill = variable)) + geom_bar(stat = “identity”, position = “stack”) + labs(y= “Abundance”)

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=proportion, fill = variable)) + geom_bar(stat = “identity”, position = “stack”) + labs(y= “Abundance”, colour = “Domain”)

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=proportion, fill = variable)) + geom_bar(stat = “identity”, position = “stack”) + labs(y= “Abundance”, legend = “Domain”)

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=proportion, fill = variable)) + geom_bar(stat = “identity”, position = “stack”) + labs(y= “Abundance”, Colour = “Domain”)

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=proportion, fill = variable, trans = log10(proportion))) + geom_bar(stat = “identity”, position = “stack”) + labs(y= “Abundance”, fill = “Domain”)

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=log10(proportion), fill = variable, )) + geom_bar(stat = “identity”, position = “stack”) + labs(y= “Abundance”, fill = “Domain”)

Warning message:

Removed 4 rows containing missing values (geom_bar).

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=log10(proportion), fill = variable, )) + geom_bar(stat = “identity”, position = “stack”) + labs(y= “Abundance(log transformed)”, fill = “Domain”)

The successful code:

> mytable %>% mutate(percentage = proportion/mean(proportion)*100)%>% ggplot(aes(x=Environment, y=log10(proportion), fill = variable, )) + geom_bar(stat = “identity”, position = “stack”) + labs(y= “Abundance (log10 transformed)”, fill = “Domain”)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s