0

The code I used and the result can be seen in the image below. The main problem is that the title doesn't appear in the center and the x and y labels don't appear at all. How do I fix this?

The graph and code

enter image description here

Tung
  • 26,371
  • 7
  • 91
  • 115
StackUser
  • 1
  • 3
  • Please post your data and code as text that folks here can copy. [See here](https://stackoverflow.com/q/5963269/5325862) on how to post an R question that is easy to reproduce and respond to – camille May 19 '18 at 16:26
  • The position of titles and labels are theming issues. Looking at the [manual page online](http://www.sthda.com/english/rpkgs/ggpubr/reference/ggballoonplot.html) shows balloon plots without x and y labels, leading me to believe these aren't created by default, and that you instead have to set them yourself with something like `xlab`. Manual pages are always a good place to start your research – camille May 19 '18 at 17:25
  • @Camille, Tried that as well but it ends up not graphing anything and just gives me white plot – StackUser May 19 '18 at 17:41
  • Okay, then you're going to need to post your data and code as text for us to help further – camille May 19 '18 at 17:43

1 Answers1

0

You should upload your code as a snippet and your data so we can reproduce this on our own machines easily...

Take the example below. You can recreate the data set and then run the code immediately.

Using ggtitle, xlab, ylab you can plot the text and center it with theme.

If this does not help you have the wrong print / render settings.

balloon <- data.table(structure(list(Genera = c("Prevotella", "Treponema", "Fusobacterium","Selenomonas", "Veillonella", "Porphyromonas", "Streptococcus","Leptotrichia", "Aggregatibacter", "Succiniclasticum"), S1 = c(97L,28L, 11L, 40L, 5L, 13L, 10L, 24L, 0L, 16L), S3 = c(5370L, 3760L,5551L, 2087L, 533L, 873L, 1330L, 5877L, 1213L, 44L), S4 = c(7892L,8004L, 11017L, 19712L, 5115L, 2695L, 7451L, 13611L, 301L, 2557L), S5 = c(23L, 79L, 30L, 7L, 0L, 34L, 0L, 2L, 2L, 0L), S6 = c(8310L,3379L, 38058L, 1133L, 2506L, 17811L, 12103L, 403L, 668L, 3L),S2 = c(7379L, 14662L, 10085L, 148L, 1502L, 5222L, 1010L,2463L, 4790L, 28L), S7 = c(6238L, 18977L, 2674L, 2198L, 27L,2999L, 174L, 1197L, 5268L, 5L), S8 = c(20019L, 18674L, 15306L,1472L, 1898L, 9600L, 1683L, 2221L, 3435L, 1109L), S9 = c(153L,12L, 23L, 36L, 15L, 15L, 6L, 41L, 0L, 30L), S10 = c(20103L,29234L, 10857L, 2869L, 4923L, 14206L, 1415L, 4574L, 649L,2160L)), .Names = c("Genera", "S1", "S3", "S4", "S5", "S6","S2", "S7", "S8", "S9", "S10"), class = c("data.table", "data.frame"), row.names = c(NA, -10L))) 

library(ggplot2)
library(reshape2)
library(data.table)
balloon<-fread("Downloads/balloon.csv")
balloon
balloon_melted<-melt(balloon)
head(balloon_melted)
p <- ggplot(balloon_melted, aes(x =variable, y = Genera)) 
p+
  geom_point( aes(size=value))+
  theme(panel.background=element_blank(), 
        panel.border = element_rect(colour = "blue", fill=NA, size=1)) +
  ggtitle("Pretty title") + 
  xlab("x lab label") +
  ylab("y lab label") +
  theme(plot.title = element_text(hjust = 0.5))
Jonathan
  • 148
  • 1
  • 10