I was wondering how the y axis of a ggplot can be altered in a way that the distance between factors increases or deacreases hetergenous.
x<-c(1:5)
y<-c("Randall","Donavan","Molly","Timothy","Barbara")
plot <- ggplot(df, aes(x = x, y = y))
geom_point()
plot
How can one produce a plot with for example "Randall" and "Donavan" close together and "Timothy" and "Barbara" close togehter but a with a big gab between them.
I do not just want to move the labels but alter the differences between the factors.
CodePudding user response:
You should set different values to the breaks
of different labels
in your scale_y_continuous
command in ggplot
. You can use the following code as an example:
library(tidyverse)
df <- data.frame(
x = c(1:5),
y = c("Randall","Donavan","Molly","Timothy","Barbara"),
dist = c(1, 2, 4, 8, 9))
plot <- ggplot(df, aes(x = x, y = dist))
geom_point()
scale_y_continuous(breaks = df$dist, labels = df$y)
plot
Output:
As you can see, the labels are on a different scale. Donavan and Randall close, Barbara and Timothy close and big gap between each others.