下面的代码应该旋转并对齐x轴上的文本标签,但由于某种原因,它不会:
ggplot(res, aes(x=TOPIC,y=count), labs(x=NULL)) +
scale_y_continuous(limits=c(0,130),expand=c(0,0)) +
scale_x_discrete("",labels=c("ANA"="Anatomy","BEH"="Behavior","BOUND"="Boundaries",
"CC"="Climate change","DIS"="Disease","EVO"="Evolution",
"POPSTAT"="Pop status","POPABU"="Pop abundance",
"POPTR"="Pop trend","HARV"="Harvest","HAB"="Habitat",
"HABP"="Habitat protection","POLL"="Pollution",
"ZOO"="Captivity","SHIP"="Shipping","TOUR"="Tourism",
"REPEC"="Reprod ecology","PHYS"="Physiology","TEK"="TEK",
"HWC"="HWC","PRED"="Predator-prey","METH"="Methods",
"POPGEN"="Pop genetics","RESIMP"="Research impact",
"ISSUE"="Other","PROT"="Protection","PA"="Protected areas",
"PEFF"="Protection efficiency","MINOR"="Minor")) +
theme(axis.text.x=element_text(angle=90,hjust=1)) +
geom_bar(stat='identity') +
theme_bw(base_size = 16) +
ggtitle("Peer-reviewed papers per topic")
Run Code Online (Sandbox Code Playgroud) 在这个图中我命令ylim为0,但是y轴似乎从-1开始,这非常烦人.我真的很喜欢y轴到0的统计数据.解决方案?
sub1=subset(table.popstat,POPSTAT==1,select=c(1,3))
ggplot(sub1, aes(x=YR,y=Freq)) + ylim(0,15) +
geom_bar(stat='identity') +
annotate("text",x=3,y=14.9,label="Population status",cex=10)
Run Code Online (Sandbox Code Playgroud)
另外,我有30个这样的图,y轴上有许多不同的范围.我需要一个通用代码,无论ymax是什么,都将文本放在图的左上角.可行?
我正在制作一个简单的条形图,并使用一些简单的数据重复旧脚本,但它拒绝返回图形.
这是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")
Run Code Online (Sandbox Code Playgroud)
这是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)) …Run Code Online (Sandbox Code Playgroud) 在我的原始数据文件(4600 条记录)中,日期、年、小时和分钟合并为一个大整数,例如:
1205981254(1998年5月12日12:54)
问题是每个月第 10 天和第 31 天之间的日期记录有 10 位数字,而第 1 天和第 9 天之间的日期只有 9 位数字:
905981254(1998年5月9日12:54)
多年前我还是学生时创建了这个原始数据文件,没有遵循特定的格式。如何从这些整数中提取日、月、年和时间?我已经阅读了所有以前的 Qs 和 As 没有找到我的特定问题的解决方案。
我的数据看起来像这样,有大约3300行数据:
Year Location Catch
1991 0313 45100
1989 0711 323
1991 0312 1100
1991 0313 45100
1989 0711 323
1991 0312 400
1990 0313 101000
1981 0711 623
1999 0312 410
2000 0313 145100
1987 0711 323
1987 1285 770
....
Run Code Online (Sandbox Code Playgroud)
年份涵盖1977 - 2015年期间,大约有500个不同的地点,并非每年都有数据.
我需要这样的输出,总结每个单元格的捕获量,按位置(行)和年份(列)列表:
Location '1977' '1978' '1979' '1980' '1981' '1982' '1983' ...
0312 456 11100 12560 320 4566 0 12010 ...
0313 121 100 4500 760 112 12050 100100 ...
0711 5500 6500 0 1205 1201 560 90500 …Run Code Online (Sandbox Code Playgroud)