Hi all,
I am using random forest analysis for my dataset. However, the font size of the axis text cannot be changed by adding theme and assigning the axis.text.y. If the plot fails to show the bars, that's because the dataset is too small. But please take a look at the font size that I intended to change.
library(party)
> test
# A tibble: 10 x 4
date gender genre group
<dbl> <chr> <chr> <chr>
1 1778 female diary s
2 1778 female journal of
3 1778 male diary s
4 1778 male diary of
5 1778 male journal s
6 1782 female diary of
7 1782 female diary s
8 1782 female journal of
9 1782 female journal s
10 1782 male journal of
col_names <- names(test)
test[,col_names] <- lapply(test[,col_names], factor)
forest.controls = cforest_control(ntree = 500, mtry = 3)
levels(test$group)
set.seed(10)
rows <- sample(nrow(test))
test <- test[rows,]
test$group <- relevel(test$group, ref = "s")
test.forest <- cforest(group ~ date + gender + genre, data = test, controls = forest.controls)
forest.varimp <- varimp(test.forest, conditional = TRUE)
rf.varimp <- data.frame(Imp=forest.varimp, Preds = factor(names(forest.varimp), levels=names(sort(forest.varimp))))
ggplot(rf.varimp[1:3,], aes(Preds,Imp)) + coord_flip() +
geom_hline(yintercept=abs(min(rf.varimp$Imp)), linetype="dashed") +
geom_bar(stat="identity", fill="gray", color="black", width=0.7) +
labs(x="Predicators", y="Predictor Importance") +
theme(axis.text.y = element_text(size = 20)) +
theme_bw()
Many thanks in advance for your help!