Tag: ggplot2

在ggplot2中绘制线条和群体审美

这个问题是从前面的问题及其答案开始的。 首先一些玩具数据: df = read.table(text = "School Year Value A 1998 5 B 1999 10 C 2000 15 A 2000 7 B 2001 15 C 2002 20", sep = "", header = TRUE) 最初的问题是如何为每所学校绘制价值年线。 答案或多或less对应于下面的p1和p2。 但也要考虑p3。 library(ggplot2) (p1 <- ggplot(data = df, aes(x = Year, y = Value, colour = School)) + geom_line() + geom_point()) […]

在ggplot中使用预定义的调色板

有谁知道如何在ggplot中使用预定义的调色板? 我有一个颜色vector我想用: rhg_cols <- c("#771C19", "#AA3929", "#E25033", "#F27314", "#F8A31B", "#E2C59F", "#B6C5CC", "#8E9CA3", "#556670", "#000000") 但是当我试图通过它没有发生 ggplot(mydata, aes(factor(phone_partner_products)), color = rhg_cols) + geom_bar()

如何安装R包github版本库的开发版本

我如何直接从github存储库安装正在开发的软件包,并且一旦安装后,如何在开发和CRAN版本之间切换? 我有兴趣从git安装的特定软件包是ggplot2。

ggplot,在各个面之间的点之间画线

使用ggplot2,我如何绘制在各个方面之间运行的趋势线。 library(ggplot2) df <- data.frame(y=c(1,2,3),x=1,Set=LETTERS[1:3]) ggplot(df,aes(x,y)) + theme_bw() + theme(legend.position=c(0,1),legend.justification=c(0,1)) + geom_point(aes(fill=Set),color="black",shape=21,size=3) + facet_grid(~Set) + xlim(1,5) 其中产生以下内容: 在上面,我想在三点之间划一条线,穿过各个方面。

RE:使用ggplot2将各个栏上的数字alignment

我有需要在ggplot上的标签上方放置标签。 我曾经使用find的方法( 这里 ),但这似乎不起作用了,因为我ggplot2更新,因为我现在得到错误消息: Error in continuous_scale(c("y", "ymin", "ymax", "yend", "yintercept", : unused argument(s) (formatter = "percent") 如何在使用示例时再次在条上方绘制数值: df <- structure(list(A = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L), .Label = c("0-50,000", "50,001-250,000", "250,001-Over"), class = "factor"), B = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("0-50,000", "50,001-250,000", "250,001-Over"), […]

ggplot单独的传说和情节

我正在使用网格 lpackage放置我用ggplot2制作的graphics : library(ggplot2) library(grid) Layout <- grid.layout(nrow = 4, ncol = 4, widths = unit(1, "null"), heights = unit(c(0.4, 0.8, 1.2, 1.2), c("null", "null", "null"))) grid.show.layout(Layout) plot1 = ggplot(diamonds, aes(clarity, fill = color)) + geom_bar() + facet_wrap(~cut, nrow = 1) print(plot1 + theme(legend.position = "none"), vp = viewport(layout.pos.row = 3, layout.pos.col = 1:4)) 问题是我想把第三行(3,1) […]

ggplot2条形图的多个子组

我正在尝试生成具有多个因素分组的条形图。 我尝试创build的一个例子来自于品种和灌溉处理的细分: 我知道我可以使用facet_wrap()生成多个图表,但是我想为多年的类似数据生成同一types数据的多个图表。 我在这个例子中使用的数据的一个例子: Year Trt Variety geno yield SE 2010-2011 Irr Variety.2 1 6807 647 2010-2011 Irr Variety.2 2 5901 761 2010-2011 Irr Variety.1 1 6330 731 2010-2011 Irr Variety.1 2 5090 421 2010-2011 Dry Variety.2 1 3953 643 2010-2011 Dry Variety.2 2 3438 683 2010-2011 Dry Variety.1 1 3815 605 2010-2011 Dry Variety.1 […]

ggplot2 – 与堆叠和闪避条形图

我正在尝试使用ggplot2创build一个barplot,在这里我通过一个variables进行堆栈,然后通过另一个variables进行躲避。 这是一个示例数据集: df=data.frame( year=rep(c("2010","2011"),each=4), treatment=rep(c("Impact","Control")), type=rep(c("Phylum1","Phylum2"),each=2), total=sample(1:100,8)) 我想创build一个barplot,其中x=treatment , y=total ,堆栈variables是type ,闪避variables是year 。 当然,我可以做一个或另一个: ggplot(df,aes(y=total,x=treatment,fill=type))+geom_bar(position="dodge",stat="identity") ggplot(df,aes(y=total,x=treatment,fill=year))+geom_bar(position="dodge",stat="identity") 但不是两个! 感谢任何能提供build议的人。

点在ggplot的x轴上剪切

我正在绘制一个时间序列,用一个响应variables的平均值作为按月(x轴)的点(y轴)。 位于x轴上的值(即0值)被剪切。 我可以改变Y轴的限制,以包括一些低于0的填充,但我不喜欢。 有没有办法在x轴的前面或顶部绘制这些0点?

在ggplot2中将facet标签更改为math公式

我不知道如何将ggplot2的facet标签更改为math公式。 d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) + xlim(0, 2) + stat_binhex(na.rm = TRUE) + opts(aspect.ratio = 1) d + facet_wrap(~ color, ncol = 4) 例如,我想将facet标签从D更改为Y[1] ,其中1是下标。 在此先感谢您的帮助。 我find了这个答案,但它不适合我。 我使用R 2.15.1和ggplot2 0.9.1 。