Setting Axes Names in ggplot2

Hi All,

I've been following an unsupervised random forest (RF) routine. Unsupervised Random Forest Example - Daniel Oehm | Gradient Descending

In standard unsupervised RF fashion: the RF proximity matrix is extracted, and then clustered using something like partitioning around medoids (PAM).

Thus far, I don't have a problem with the implementation. My only problem is labelling the axes on the cluster plot.

I would like unlabelled axes, or axes simply labelled X, and Y. (instead of the two dimensions of the iris dataset).

Would someone be able to show me how to recode the ggplot below to present the axes as unlabelled, or simply as X and Y, please?

Would be massively appreciated.


install.packages("randomForest")
install.package("caret")
install.packages("cluster")
install.packages("RColorBrewer")
install.packages("ggplot2")
install.packages("dplyr")

#LOAD PACKAGES 

library(randomForest)
library(caret)
library(cluster)
library(RColorBrewer)
library(ggplot2)
library(dplyr)

#SET COLOUR FORMAT

mycol <- colorRampPalette(colors = c("#25591f","#818c3c", "#72601b"))

#DATA

data(iris)

#UNSUPERVISED RANDOM FOREST

rf <- randomForest(iris[,-5], mtry = 2, ntree = 100, proximity = TRUE) 

#PROXIMITY MATRIX

prox <- rf$proximity

#PAM WITH 3 CLUSTERS

pam.rf <- pam(prox, 3)

#GGPLOT

Clusters <- as.factor(pam.rf$cluster)
Species <- iris$Species
ggplot(iris, aes(x = Petal.Length, y = Petal.Width, col = Clusters, pch = Species)) + geom_point(size = 3) + 
  scale_color_manual(values = mycol(3))

A simple way to not have axies titles is to add + labs(x = "", y = "") to your plot.

ggplot(iris, aes(x = Petal.Length, y = Petal.Width, col = Clusters, pch = Species)) + geom_point(size = 3) + 
  scale_color_manual(values = mycol(3))  + labs(x = "", y = "")

On a side note, pch is not an aesthetic in ggplot. I think you need to replace that with shape.

Thanks @FJCC. It works. Nice tip :slight_smile:

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.