0

I am polotting a value and its confidence interval for each test on certain data. x-axis data, y-axis tests.

It takes a lot of space in documentation, i would rather move the y-axis labels to top of the image and arrange the tiles horizontally. geom_tiles

Here is the code that i was using

 p <- ggplot(data, aes(x= DATA, #y=reorder(TEST, VALUE), fill = VALUE))+ geom_tile(colour = 'White', aes(y=TEST, height = 1)) + scale_fill_continuous(na.value = 'salmon')+ guides(fill=guide_legend(title='Tiles'))+ scale_fill_continuous(high = "#4292C6", low = "#C6DBEF")+ #coord_fixed(ratio = 0.1) + xlab("Data") + ylab('Test') + labs(color = 'AUROC') + # geom_text(aes(y=TEST,label = paste0(round(VALUE, 4),'\n','[',CI,']')), size = 4.7, fontface = 'bold') + # ggtitle(name)+ theme_bw()+ ggtitle('Data vs Test') + #theme(aspect.ratio = 1/5) + theme(axis.text=element_text(size=18), axis.title=element_text(size=24), plot.title = element_text(size=26)) + theme(legend.key.size = unit(2,"line"), legend.title = element_text(size=24), legend.text = element_text(size=16)) #legend.position = 'bottom', legend.direction="horizontal") plot(p) 

what changes shall i make to arrange the tiles horizontally? Edit: enter image description here

4
  • 1
    I'm having a bit of trouble imagining what the desired output is. Can you find an example of what you like the output to be or make drawing of what is should become? Commented Aug 25, 2021 at 8:13
  • @teunbrand Thanks for quick response. I added a dummy image, how i would like to have. Commented Aug 25, 2021 at 8:20
  • 2
    Doesn't replacing y=TEST by y=1 give something close to what you like? Commented Aug 25, 2021 at 8:23
  • it did! thanks. how can add y labels on top of the plot? can you post it as an answer? I would accept it as answer. Commented Aug 25, 2021 at 8:27

1 Answer 1

2

You can replace y=TEST by y=some_constant to have all the tiles line up in a row. The x-axis can be placed at the top by setting position = 'top' in the scale. Simplified example below:

library(ggplot2) set.seed(42) df <- data.frame( DATA = factor(1:10), TEST = factor(1:10), VALUE = rnorm(10) ) ggplot(df, aes(DATA, y = 1)) + geom_tile(aes(fill = VALUE), colour = "white") + geom_text(aes(label = round(VALUE, 4))) + scale_x_discrete(position = 'top') 

Created on 2021-08-25 by the reprex package (v2.0.1)

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

2 Comments

The solution worked for me and its perfect. I would like to have x-lables on the bottom and correspoding y lables on the top.
Discrete scales don't support secondary axes. To be clear, you cannot have the y-axis labels on the x-axis. You can make a discrete-like axis from a continuous scale and then use the secondary axis to label the top differently from the bottom.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.