Adjusting font size of axis labels in levelplot function in R

14,344

Solution 1

And THE WINNER IS:

pdf('corr.pdf')
data <- read.table("test", header=T)
z <- cor(data)
heatmap.2(z, Rowv=FALSE, Colv=FALSE, dendrogram="none", 
          key=TRUE, density.info="none", trace="none", 
          col=colorpanel(100, lowColor, highColor), scale="none",cexRow=0.3, cexCol=0.3 )
dev.off()

Solution 2

EDIT: Take the first example from the levelplot manual and change the scales=list(log="e") argument to scales=list(log="e",x=list(cex=.3),y=list(cex=.3)):

x <- seq(pi/4, 5 * pi, length.out = 100)
y <- seq(pi/4, 5 * pi, length.out = 100)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x=x, y=y)
grid$z <- cos(r^2) * exp(-r/(pi^3))
levelplot(z~x*y, grid, cuts = 50, 
      scales=list(log="e",x=list(cex=.3),y=list(cex=.3)), xlab=list(cex=.05),
      ylab=list(cex=.25), main=list(label="Weird Function", cex=5), sub="with log scales",
      colorkey = FALSE, region = TRUE)

This will reduce the axis labels' font sizes with a factor of .3.

Solution 3

You can correct this with

pdf('corr.pdf', width=100, height=100)
data <- read.table("test", header=T) 
z <- cor(data)
levelplot(z)
dev.off()
Share:
14,344
Angelo
Author by

Angelo

Updated on June 14, 2022

Comments

  • Angelo
    Angelo about 2 years

    I have matrix of 90 by 90 and I am trying to get an array correlation matrix. Using the following command:

    pdf('corr.pdf')
    data <- read.table("test", header=T) 
    z <- cor(data)
    levelplot(z)
    dev.off() 
    

    I get an image like this and my tags are getting smudged enter image description here

    Please give your suggestions to improve the image.

    Thank you

  • Angelo
    Angelo about 12 years
    No, I don't have to edit the size of headings. I want to edit the size of the labels of x and y axis. which are smudged right now.
  • Angelo
    Angelo about 12 years
    Thanks. Problem is partially solved. How can I vertical labels at x axis which are now horizontal.
  • TemplateRex
    TemplateRex about 12 years
    @Angelo OK, I see. I edited your question to reflect that meaning, and changed the answer above.
  • Angelo
    Angelo about 12 years
    This is what the command looks like now:levelplot(z,scales=list(log="e",x=list(cex=.3),y=list(ce‌​x=.3))) and I get this new error Error in log(lim, base) : Non-numeric argument to mathematical function
  • TemplateRex
    TemplateRex about 12 years
    @Angelo Perhaps you can give a full working example (with a small random dataset) to illustrate what goes wrong exactly.
  • solvingPuzzles
    solvingPuzzles almost 12 years
    Note that Heatmap isn't quite the same thing as Levelplot (the OP asked about Levelplot). Heatmap uses adds contoured lines for interpolation; Levelplot draws the data in a grid without any embellishments. Also, I'm not sure that Levelplot recognizes the cexRow and cexCol parameters, but I could be wrong.