1

I successfully plot my data using ggplot() in R. However, when I choose to have the y- and x- axis in log10 scaling, the first tick on the y-axis (0.01) is further apart for the intersection than the first tick on the x-axis (0.01). I need the x-axis to have the same "scaling" as the y-axis.

Here is my code. Also the data (use sep="\t"). And an image of how the graph looks for me. Im sorry the data is on an external link, I couldnt figure out how to give it to you as reproducible data otherwise!

FILE1 <- read.delim("example.txt", sep="\t", header = TRUE)

EXAMPLE_PLOT <- ggplot(FILE1, aes_string(x = colnames(FILE1)[1], y = colnames(FILE1)[2])) + 
  geom_point(size=4) + 
  ggtitle("EXAMPLE_PLOT") + 
  theme(plot.title = element_text(family="Calibri", color="black", 
                                  face="bold", size = 32, hjust=0)) +
  theme(plot.background= element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank())+
  theme(panel.background = element_blank())+
  theme(axis.line.x = element_line(color="black", size = 1),
        axis.line.y  = element_line(color="black", size = 1))+
  theme(axis.ticks  = element_line(color="black", size = 1))+
  theme(axis.ticks.length = unit(0.3,"cm"))+
  theme(axis.title = element_text(family = "Calibri",
                                  color="black", size=17, face="bold"))+
  theme(axis.text.x = element_text(family = "Calibri", color="black",
                                   size=14, face="bold"),
        axis.text.y = element_text(family = "Calibri", color="black",
                                   size=14, face="bold"))+
  scale_x_log10(breaks=c(.01, .1, 1, 10, 100))+
  scale_y_log10(breaks=c(.01, .1, 1, 10, 100))+
  geom_smooth(method=lm)

EXAMPLE_PLOT

THE DATA

enter image description here

0

1 Answer 1

1

You forgot to add limits in the scale_x_log10 and scale_y_log10:

enter image description here

FILE1 <- read.delim("example.txt", sep="\t", header = TRUE)

EXAMPLE_PLOT <- ggplot(FILE1, aes_string(x = colnames(FILE1)[1], y = colnames(FILE1)[2])) + 
  geom_point(size=4) + 
  ggtitle("EXAMPLE_PLOT") + 
  theme(plot.title = element_text(family="Calibri", color="black", 
                                  face="bold", size = 32, hjust=0)) +
  theme(plot.background= element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank())+
  theme(panel.background = element_blank())+
  theme(axis.line.x = element_line(color="black", size = 1),
        axis.line.y  = element_line(color="black", size = 1))+
  theme(axis.ticks  = element_line(color="black", size = 1))+
  theme(axis.ticks.length = unit(0.3,"cm"))+
  theme(axis.title = element_text(family = "Calibri",
                                  color="black", size=17, face="bold"))+
  theme(axis.text.x = element_text(family = "Calibri", color="black",
                                   size=14, face="bold"),
        axis.text.y = element_text(family = "Calibri", color="black",
                                   size=14, face="bold"))+
  scale_x_log10(breaks=c(.01, .1, 1, 10, 100), limits = c(0.01,10))+
  scale_y_log10(breaks=c(.01, .1, 1, 10, 100), limits = c(0.01,10))+
  geom_smooth(method=lm) 

EXAMPLE_PLOT
Sign up to request clarification or add additional context in comments.

5 Comments

It works if I write limits = c(0.01,100), do not change your breaks (keep 100).
Thank you! It worked out! To people reading this now, I accidentally deleted my additional question. I wanted the scale to go all the way to 100.
Okay, now I cant save it with ggsave() anymore. It worked before this change. I get following error: Error in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y, : invalid font type
In my case, I still can use ggsave() with this plot. Be sure your last plot is EXAMPLE_PLOT, or use ggsave("plot_.jpg",EXAMPLE_PLOT)
EDIT: I fixed it by removing every 'family =' command and just leaving it to the default

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.