Pavel Shliaha
Pavel Shliaha

Reputation: 935

make a table as x axis label in ggplot2

so I have a geom_tile and I need to label columns. Each label has the following form:

value1_value2_value3_value_4_value_5. If I label like this the text is very cumbersome to read. Is there any way to have all the labels appear as a column of text like this:

value1
value2
value3
value4
value5

baxically making a table?

Upvotes: 1

Views: 153

Answers (1)

pogibas
pogibas

Reputation: 28339

Maybe I don't get something, but can't you replace _ with a newline? For example:

foo <- paste0("value", 1:5)
paste(foo, collapse = "\n")
[1] "value1\nvalue2\nvalue3\nvalue4\nvalue5"

And it will appear as:

value1
value2
value3
value4
value5

If your labels already are in value1_value2_value3_value_4_value_5 format you can do this:

gsub("_", "\n", "value1_value2_value3_value_4_value_5")

Upvotes: 1

Related Questions