r - ggplot change x-axis labels without changing underlying data -
i plotting facets , discrete data on x-axis. how can change x-axis labels without changing underlying data? i.e. instead of labels reading "a","b","c","d"
should read "lab 1","lab 2","lab 3","lab 4"
.
df <- data.frame(x = factor(rep(c("a","b","c","d"),4), levels = c("a","b","c","d")), y = rep(seq(1,8,1),2), z = c(rep("x",4),rep("y",4)), facet = rep(c(rep("1",2),rep("2",2)),4)) ggplot(null) + geom_line(data=df, aes(y=y, x=x, linetype=z, group = z, colour=z)) + facet_grid(~facet, scales="free_x", space="free_x") + scale_colour_manual(values=c("red","blue")) + scale_linetype_manual(values=c("solid", "dashed"))
you can use named character vector labels
argument in scale_x_discrete
.
scale_x_discrete(labels = c("a" = "lab 1", "b" = "lab 2", "c" = "lab 3", "d" = "lab 4") )
alternatively, give both breaks
, labels
scale_x_discrete(breaks = c("a", "b", "c", "d"), labels = c("lab 1", "lab 2", "lab 3", "lab 4") )
Comments
Post a Comment