简体   繁体   中英

missing plot title in ggplot2

How can I create a plot title in ggplot2? Am I making a silly syntax error?

The ggplot2 docs indicate that labs(title = 'foo') should work, but I can only get the arguments x='foo' and y='foo' to work with labs() . Neither ggtitle() nor title() worked either.

Here is an example.

x <- rnorm(10,10,1)
y <- rnorm(10,20,2)
xy.df <- data.frame(x,y)
qplot(x,y, data=xy.df, geom='point', color=x*y) + 
  labs(title = "New Plot Title",
       x='Some Data', 
       y='Some Other Data')

You could use the main argument in the function qplot :

qplot(x,y, data=xy.df, geom='point', color=x*y, main = "New Plot Title") + 
  labs(x='Some Data', 
       y='Some Other Data')

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM