Can't use "aes" function

Hi,

I'm trying to move my point labels so that the labels don't overlap the points. I am using the "geom_text_repel" to complete this, which requires the "aes()" function in order to work. However, the "aes()" function isn't available on my R version. Is there another way to stop my labels from overlapping with the data points? Thanks in advance.

I think rather than use points you should be using ggplot2 which can interact with geom_text_repel , and that knows what aes is.
aes is not a package.

library(ggplot2) # install.packages("ggplot2") if needed

okay, let me try that

I updated ggplot2 but now I keep getting this...

Error in ggplot2(phylum.t2.dca, display = "site", choices = 1:2, pch = c(15,
could not find function "ggplot2"

Can you provide your full code using ggplot2?

I'm brand new at coding so this ggplot2 code may look like crap:

ggplot2(phylum.t2.dca, display = "site", choices = 1:2, pch = c(15, 16, 17), col = point_colors) + ggrepel::geom_text_repel(aes(phylum.t2.dca))

Here is my full code:

#Updated DCA Analyses

WD <- "C:/Users/"

setwd(WD)

require(vegan)

phylum.dat <- read.csv("Phylum data for R.csv", stringsAsFactors = T, header = T, row.names = 1) # preform dca on data set

phylum.t1 <- decostand(phylum.dat, "total") # percent transformation on samples; “total” method defaults to rows (samples)

phylum.t2 <- decostand(phylum.t1, "max") # percent of maximum transformation on taxa; “max” method defaults to columns (taxa)

phylum.t2.dca <- decorana(phylum.t2) # default ira=0 specifies DCA

phylum.t2.dca.DW <- decorana(phylum.t2, iweigh = 1) # iweigh=1 turns on down-weighting of rare taxa, dampening their effects on the ordination

names(phylum.t2.dca) # view items in list produced by decorana

summary(phylum.t2.dca) # view summary of dca results

phylum.t2.dca.taxonscores <- scores(phylum.t2.dca,display=c("species"), choices=c(1,2)) # extract scores from decorana output; extracts axis 1 & 2 scores for taxa

plot(phylum.t2.dca, display = "sites", type = "text", main = "Phylum") # adds site names

point_colors <- c(rep("blue", 4), rep("red", 4), rep("green", 4)) # assign colors

points(phylum.t2.dca, display = "site", choices = 1:2, pch = c(15, 16, 17), col = point_colors) # plot points

text(phylum.t2.dca, display = "species", choices = 1:2, cex = 0.6, col = "darkcyan") # plot labels for taxa

ggplot2(phylum.t2.dca, display = "site", choices = 1:2, pch = c(15, 16, 17), col = point_colors) + ggrepel::geom_text_repel(aes(phylum.t2.dca)) # separate label overlap

ggplot2 has a particular syntax that it would benefit you to study. The following chapter quite rapidly catches you up to speed with good examples.

1 Like

I feel like I cannot use ggplot2 because DCA isn't a scatterplot or boxplot or bar graph

It looks like a scatterplot with some polygons drawn on it to me.

I believe you need the command "ggplot" not "ggplot2" which is the name of the library/package.

Try

library(ggplot2)

ggplot(phylum.t2.dca, display = "site", choices = 1:2, pch = c(15, 16, 17), col = point_colors) + ggrepel::geom_text_repel(aes(phylum.t2.dca)) # separate label overlap

I think you need a dataframe with data to be plotted in rows and columns. What I think you have is an object of type decorana. To get ggplot2 to work you will need to calculate DCA1 and DCA2 for each observation. Then ggplot(dataframe, aes(x=DCA1, y=DCA2)) + geom_point() will work. If you want a quick start and do not care how many packages are used then try this:
if(!require(ggfortify))[install.packages(ggfortify} #tests if ggfortify is installed, and installs it if not.
library(ggfortify) #links the package to your code.
With that addition this link should be useful:
https://rdrr.io/github/gavinsimpson/ggvegan/man/autoplot.decorana.html
You will use the autoplot function in the ggfortify package which itself is a front end to ggplot.
However, I would echo some other posts and suggest that you learn ggplot2. Sometimes knowing the right package can make things much simpler. The problem is that all your code goes bad when that package is no longer supported, or you are the lone user of some archaic version of R.

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.