ggplot layout and figure limits
0
0
Entering edit mode
24 months ago
lynnchen31 • 0

I want to make a plot which I want the figure height to be exactly the 1.5 times of the figure width. Also, I want the x-axis and y-axis use the same unit. Here is my code of 3 figures on one pdf.

   # met1 is a dataframe
    a = 1.1*max(met1$x)
    b = (a*1.5)

    canvas_height = 14 
    canvas_width = 30

p1 <- ggplot(met1, aes(x = x, y = y)) + 
  geom_point(aes(colour = nCount_spatial),size=0.8) +
  scale_x_continuous(labels = label_number(suffix = "K", scale = 1e-3), limits = c(0,a), expand = c(0,0))+
  scale_y_continuous(labels = label_number(suffix = "K", scale = 1e-3),limits = c(0, b), expand = c(0,0))+
  scale_color_gradient(low = "lightblue", high = "darkblue",name='MID',
                       labels=label_number(suffix = "K", scale = 1e-3)) +
  labs(title='MolecularID heatmap')+
  theme(axis.title = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        axis.text=element_text(size=12))

pdf(file = paste(out_path,"/Plot.pdf', sep = ''), w = canvas_width, h = canvas_height)
p1 + p1 + p1
dev.off()

Here is the plot I got: enter image description here

You will see each figure height is near 1.5 times of the figure width. However, the physical length from 0 to 3k on x-axis and on y-axis are actually not the same.

How do I make the the physical length from 0 to 3k on x-axis and on y-axis are the same, while still maintain the figure height is 1.5 times of the figure width in each figure? If anyone can share their idea and codes how to generate the plot, that will be really great.

Appreciate your help in advance.

Best,
LC

ggplot2 • 456 views
ADD COMMENT

Login before adding your answer.

Traffic: 4554 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6