我很抱歉问一个之前在 SO 上问过的问题,但我试图 在 ggplot2中绘制一些简单的数据,并且无法沿 x 轴对数据进行分箱。我的数据由旧书中的视觉元素(图表、版画等)组成,我可以绘制每年每种视觉元素的频率:
#this works
df <- read.table("cleaned_estc_visuals.txt",
header = F,
sep = "\t")
ggplot(data=df, aes(x=V1, y=V3)) +
geom_bar(aes(fill=V2),stat="identity") +
labs(title = "Visuals in Early Modern Books",fill="") +
xlab("Year") +
ylab("Titles")
这产生:
为了使数据更清晰,我想将 x 轴上的值按十年排列,但似乎无法正确调用:
#this doesn't
ggplot(data=df, aes(x=V1, y=V3)) +
geom_bar(aes(fill=V2),binwidth=10,stat="bin")
运行后面的代码,我得到:
Mapping a variable to y and also using stat="bin".
With stat="bin", it will attempt to set the y value to the count of cases in each group.
This can result in unexpected behavior and will not be allowed in a future version of ggplot2.
If you want y to represent counts of cases, use stat="bin" and don't map a variable to y.
If you want y to represent values in the data, use stat="identity".
See ?geom_bar for examples. (Deprecated; last used in version 0.9.2)
Error in pmin(y, 0) : object 'y' not found
有谁知道我如何沿 x 轴按十年分档?对于其他人可以提供的任何建议,我将不胜感激。