Removing a field and changing the font style for labels in ggplot

I created a dendrogram using ggdendro and ggplot. I have two problems regarding the generated plot.

  • Is it possible to cut some stock from the generated chart?
  • How to change font style, for example, size, for a label along one axis?

On the chart, the two areas marked with a "red panel" are the fields that I would like to delete. Six labels along the x axis are marked in yellow. I would like to increase their size.

enter image description here

The code:

> x<-read.csv("test1.csv",header=TRUE) > d<-as.dist(x,diag=FALSE,upper=FALSE) > hc<-hclust(d,"ave") > dhc<-as.dendrogram(hc) > ddata<-dendro_data(dhc,type="rectangle") > ddata$labels$text <- gsub("\\."," ",ddata$labels$text) > fig1<-ggplot(segment(ddata))+geom_segment(aes(x=x0,y=y0,xend=x1,yend=y1)) > fig1<-fig1+xlab(NULL)+ylab(NULL)+opts(panel.grid.minor=theme_blank()) > fig1<-fig1+scale_x_discrete(limits=ddata$labels$text) > fig1<-fig1+coord_flip() > last_plot() > fig1<-last_plot() > ggsave("test1.pdf") 
+6
source share
1 answer

To increase the size of the axis labels (and much, much more), you use theme (in older versions of ggplot2 this was called opts() ):

 + theme(axis.text.x = element_text(size = 12)) 

will make them much bigger. To reduce the margins, you can use the expand argument:

 + scale_x_continuous(expand = c(0,0)) 

where numbers are additive and multiplicative expansion coefficients for the boundaries of the graph.

More generally, all of this is well documented in places like here or. Or you could just buy Hadley's book, which will answer almost every ggplot question you have. (Seriously.)

+6
source

Source: https://habr.com/ru/post/903428/


All Articles