ggplot2

Add text to plot with facetted bar chart

让人想犯罪 __ 提交于 2021-02-10 13:10:25
问题 My question is related to this question. I want "2014" in the 4-year facet. I tried to repeat but my code doesn't give what I want. Annotating text on individual facet in ggplot2 This is my data structure(list(Rot = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("2-year", "3-year", "4-year"), class = "factor"), Rot.Herb = structure(c(3L, 3L, 4L, 4L, 13L, 13L, 14L, 14L, 5L,

Direct labels puts labels at wrong place

。_饼干妹妹 提交于 2021-02-10 12:55:51
问题 I'm trying to do a plot with ggplot2 and trying to put labels at the right place on mean trajectories with confidence regions. Since I cannot share my data, I created a reproducible example: set.seed(456) library(ggplot2) library(directlabels) time<-1:25 df2<-data.frame(time,value=runif(2500),group=as.factor(c(rep('Alpha',1250),rep('Beta',1250)))) ggplot(df2, aes(x=time, y=value,group=group,colour=group))+ stat_summary(geom="ribbon", fun.data=mean_cl_normal,fun.args=list(conf.int=0.95), fill=

How do ggplot stat_* functions work conceptually?

喜欢而已 提交于 2021-02-10 12:36:48
问题 I'm currently trying to get my head around the differences between stat_* and geom_* in ggplot2 . (Please note this is more of an interest/understanding based question than a specific problem I am trying solve). Introduction My current understanding is that is that the stat_* functions apply a transformation to your data and that the result is then passed onto the geom_* to be displayed. Most simple example being the identity transformation which simply passes your data untransformed onto the

Unequal horizontal adjustment to title lines in ggplot

微笑、不失礼 提交于 2021-02-10 12:13:03
问题 I've got a plot with a fairly wide y-axis label, so I want to adjust the title to the left so that it's flush with the label rather than the axis (like this question) but the twist is that I have a multiline title. I've been using hjust, but it adjusts the two lines differently. For example ggplot(mtcars,aes(x=wt,y=mpg))+ geom_point()+ ggtitle("Figure: My long and winding title\nthat goes on and on and on") + ylab("My long label") + theme_bw() + theme(plot.title = element_text(size=16, hjust=

Unequal horizontal adjustment to title lines in ggplot

烂漫一生 提交于 2021-02-10 12:09:04
问题 I've got a plot with a fairly wide y-axis label, so I want to adjust the title to the left so that it's flush with the label rather than the axis (like this question) but the twist is that I have a multiline title. I've been using hjust, but it adjusts the two lines differently. For example ggplot(mtcars,aes(x=wt,y=mpg))+ geom_point()+ ggtitle("Figure: My long and winding title\nthat goes on and on and on") + ylab("My long label") + theme_bw() + theme(plot.title = element_text(size=16, hjust=

Unequal horizontal adjustment to title lines in ggplot

泪湿孤枕 提交于 2021-02-10 12:06:22
问题 I've got a plot with a fairly wide y-axis label, so I want to adjust the title to the left so that it's flush with the label rather than the axis (like this question) but the twist is that I have a multiline title. I've been using hjust, but it adjusts the two lines differently. For example ggplot(mtcars,aes(x=wt,y=mpg))+ geom_point()+ ggtitle("Figure: My long and winding title\nthat goes on and on and on") + ylab("My long label") + theme_bw() + theme(plot.title = element_text(size=16, hjust=

Unequal horizontal adjustment to title lines in ggplot

喜夏-厌秋 提交于 2021-02-10 12:04:59
问题 I've got a plot with a fairly wide y-axis label, so I want to adjust the title to the left so that it's flush with the label rather than the axis (like this question) but the twist is that I have a multiline title. I've been using hjust, but it adjusts the two lines differently. For example ggplot(mtcars,aes(x=wt,y=mpg))+ geom_point()+ ggtitle("Figure: My long and winding title\nthat goes on and on and on") + ylab("My long label") + theme_bw() + theme(plot.title = element_text(size=16, hjust=

Unequal horizontal adjustment to title lines in ggplot

旧时模样 提交于 2021-02-10 12:04:58
问题 I've got a plot with a fairly wide y-axis label, so I want to adjust the title to the left so that it's flush with the label rather than the axis (like this question) but the twist is that I have a multiline title. I've been using hjust, but it adjusts the two lines differently. For example ggplot(mtcars,aes(x=wt,y=mpg))+ geom_point()+ ggtitle("Figure: My long and winding title\nthat goes on and on and on") + ylab("My long label") + theme_bw() + theme(plot.title = element_text(size=16, hjust=

ggplot legend: change order of the automatic legend

大憨熊 提交于 2021-02-10 08:40:17
问题 I am struggling with the legend order in ggplot when there are several group of plots. Here is an example: library(ggplot2) library(data.table) data <- data.table(time = rep(1:50,4),dampingtime = rep(c(4,8,12,16),each = 50), excitation = rep(c(rep(0,10),rep(1,10),rep(0,30)),4)) data[,signal := time + .GRP, by = dampingtime] data[,dampingtime := as.factor(dampingtime)] Here I have > levels(data$dampingtime) [1] "4" "8" "12" "16" which I did accordingly to ggplot legends - change labels, order

ggplot legend: change order of the automatic legend

独自空忆成欢 提交于 2021-02-10 08:40:08
问题 I am struggling with the legend order in ggplot when there are several group of plots. Here is an example: library(ggplot2) library(data.table) data <- data.table(time = rep(1:50,4),dampingtime = rep(c(4,8,12,16),each = 50), excitation = rep(c(rep(0,10),rep(1,10),rep(0,30)),4)) data[,signal := time + .GRP, by = dampingtime] data[,dampingtime := as.factor(dampingtime)] Here I have > levels(data$dampingtime) [1] "4" "8" "12" "16" which I did accordingly to ggplot legends - change labels, order