0

我想为我的 qqplot 图放置 x 和 y 标签。但这并不成功。我的图表采用列标题而不是分配的标题。有人可以告诉我错误在哪里吗?我的脚本如下。

setwd("F:/Research/Fieldwork SL-data/Seed predation and seed no/Seed No")
seednumber<-read.csv(file="seed number -analysis 3.csv", header=TRUE, sep=',')
attach(seednumber)
names(seednumber)

[1] "国家" "研究.站点" "种子.编号"

ggplot(seednumber, aes(x = Study.Site, y = Seed.Number, colour = Country,xlab="Study Site", ylab="Number of seeds in a podr" )) + geom_boxplot()
4

1 回答 1

0

aes creates a list of unevaulated expressions that describe how variables in the data are mapped to visual properties of geoms.

xlab and ylab are not counted as visual properties of geoms, they are labels for the scales that define the x and y axes.

You can define these in numerous ways

# given a base plot
baseplot <- ggplot(seednumber, aes(x = Study.Site, y = Seed.Number, colour = Country)) +
            geom_boxplot()

1) The simplest is to use the functions labs or xlab and ylab

baseplot + labs(x = "Study Site", y = "Number of seeds in a podr")
# or
baseplot + xlab("Study Site") + ylab("Number of seeds in a podr")

note you can use labs to change the label of any scale (including those mapped in aes)

2). You have more control over the scales using the relevant scale_..._... functions

eg

baseplot + scale_x_discrete(name = "Study Site") + 
  scale_y_continuous(name = 'Number of seeds in a podr')
于 2013-07-25T02:14:10.623 回答