gpt4 book ai didi

r - 旧的 ggplot 脚本给出空白图的问题

转载 作者:行者123 更新时间:2023-12-04 09:31:59 25 4
gpt4 key购买 nike

我正在制作一个简单的条形图,并用一些简单的数据重复一个旧脚本,但它拒绝返回图表。

这是数据框的dput:

papers <- structure(list(YEAR = c(1957, 1970, 1981, 1982, 1987, 1988, 1990, 
1993, 1994, 1995, 1996, 2002, 2004, 2005, 2006, 2007, 2008, 2009,
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018), count = c(1L,
1L, 1L, 2L, 1L, 14L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 3L, 4L, 5L,
3L, 5L, 4L, 6L, 5L, 13L, 4L, 5L, 6L, 12L, 2L)), row.names = c(NA,
-27L), class = "data.frame")

这是 ggplot 脚本:

ggplot(papers, aes(x=YEAR,y=count)) + 
scale_y_continuous(limit=c(0,20),expand=c(0, 0)) +
scale_x_continuous(breaks=c(1955,1965,1975,1985,1995,2005,2015),
labels=c(1955,1965,1975,1985,1995,2005,2015)) +
geom_bar(stat="identity") +
theme(axis.text=element_text(size=10)) +
theme(panel.border = element_rect(colour = "grey50")) +
annotate("text",x=1948,y=18.5,label="ALL AREAS",
family="arial",size=5.5,hjust=0,color="black")

enter image description here

为什么它不起作用?

最佳答案

来自 ?theme

panel.border : border around plotting area, drawn on top of plot so that it covers tick marks and grid lines. This should be used with fill=NA (element_rect; inherits from rect)

所以你的代码工作正常,所有必须改变的是

theme(panel.border = element_rect(colour = "grey50", fill = NA))

enter image description here

关于r - 旧的 ggplot 脚本给出空白图的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52688760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com