have data with 21 samples (in molecule column) and 157 unique elements in gene column (80% in common), so I create a data.frame with the detected elements (gene column) for each sample, but I just want to add a single label in X axis to avoid multiples and repetitive labels in all the plot, so I add a extra samples with the name of genes in the rows (that contains all the detected elements) and create a extra column (labX, just a copy of the gene column) with NA in all samples except in genes rows (see in tail).
head(gdf)
molecule gene width start end labX
1 SAMPLE-300 BJE04_RS21740 3070 1 3070 <NA>
2 SAMPLE-300 BJE04_RS21750 1071 3071 4141 <NA>
3 SAMPLE-300 BJE04_RS21780 330 4142 4471 <NA>
4 SAMPLE-300 BJE04_RS21785 1629 4472 6100 <NA>
5 SAMPLE-300 BJE04_RS21790 243 6101 6343 <NA>
6 SAMPLE-300 cheA 2226 6344 8569 <NA>
tail(gdf)
molecule gene width start end labX
3257 genes wbjD/wecB 1080 175076 176155 wbjD/wecB
3258 genes mshA 471 176156 176626 mshA
3259 genes VV1_RS01700 669 176627 177295 VV1_RS01700
3260 genes VV1_RS01705 513 177296 177808 VV1_RS01705
3261 genes VV1_RS15585 282 177809 178090 VV1_RS15585
3262 genes VV1_RS15620 879 178091 178969 VV1_RS15620
You can see that only genes rows (in molecule column) presented the labels in column labX, so to make the plot:
ggplot(gdf, aes(xmin = start, xmax = end, y = molecule) ) +
geom_gene_arrow(arrowhead_width = grid::unit(7, "mm"),
arrowhead_height = grid::unit(7, "mm"),
arrow_body_height = grid::unit(5.7, "mm"), size=0.4 ) +
scale_y_discrete(position="right") +
geom_text(data=gdf %>% mutate(start = (start + end)/2),
aes(x=start, label = labX), angle=45) +
theme(panel.background = element_rect(fill = 'white', color = 'white'))
with the previous code, the label are over the arrows, but I want the labels in X axis, something like:
Move the label (in the green arrow) to x.axis (blue arrow) and eliminate the numbers (red arrow)
I tried to use scale_x_discrete:
I will use gene column that is the same than labX but with characters for each row !!!
ggplot(gdf, aes(xmin = start, xmax = end, y = molecule) ) +
geom_gene_arrow(arrowhead_width = grid::unit(7, "mm"),
arrowhead_height = grid::unit(7, "mm"),
arrow_body_height = grid::unit(5.7, "mm"), size=0.4 ) +
scale_y_discrete(position="right") +
scale_x_discrete(breaks = formatC(1:length(unique(gdf$gene)) ,
width = 2, flag = "0"),
labels = unique(gdf$gene) )
and it didn't show the labels !!!
I think that maybe the problem is expand the limits !!
Any advise ??!!
thanks