ggplot2

Missing tooltips and redundant legend with ggplotly using geom_bar

坚强是说给别人听的谎言 提交于 2021-02-05 06:55:06
问题 I'm trying to reproduce the ggplot geom_bar example I found here. The code is rather simple library(ggplot2) library(plotly) dat <- data.frame( time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")), total_bill = c(14.89, 17.23)) # No legend, since the information is redundant ggplot(data=dat, aes(x=time, y=total_bill, fill=time)) + geom_bar(colour="black", stat="identity") + guides(fill=FALSE) ggplotly() In the ggplot the fill-legend is hidden as expected but the plotly differs from

How to change the chart title dynamically in R?

元气小坏坏 提交于 2021-02-05 06:48:26
问题 Here is an example using mtcars to split by a variable into separate plots. What I created is a scatter plot of vs and mpg by splitting the data set by cyl . First an empty list is created. Then I used lapply to loop through the values of cyl (4,6,8) and then filter the data by that value. After that I plotted the scatter plot for the subset and saved it to the empty list. library(dplyr) library(ggplot2) gglist <- list() gglist <- lapply(c(4,6,8), function(x){ ggplot(filter(mtcars, cyl == x))

loop over dataframes in ggplot2

你。 提交于 2021-02-05 06:13:39
问题 I would like to make a series of plots using ggplot from multiple different dataframes. I was planning on using a list and iterating over the list as follows: libraries <- objects() #make a list of the dataframes we want to graph for(i in libraries) { # create initial plots x1 <- qplot(data= i, V1, reorder(V2,V3), color = V3) + coord_flip() x2 <- ggplot(i, aes(x=reorder(V2,V3), group=V3, color=V3)) + geom_bar() x3 <- ggplot(i, aes(x=V1, group=V3, color=V3)) + coord_flip() + geom_bar() }

loop over dataframes in ggplot2

安稳与你 提交于 2021-02-05 06:13:05
问题 I would like to make a series of plots using ggplot from multiple different dataframes. I was planning on using a list and iterating over the list as follows: libraries <- objects() #make a list of the dataframes we want to graph for(i in libraries) { # create initial plots x1 <- qplot(data= i, V1, reorder(V2,V3), color = V3) + coord_flip() x2 <- ggplot(i, aes(x=reorder(V2,V3), group=V3, color=V3)) + geom_bar() x3 <- ggplot(i, aes(x=V1, group=V3, color=V3)) + coord_flip() + geom_bar() }

ggplot2: Adding a geom without affecting limits

大憨熊 提交于 2021-02-05 05:26:06
问题 I would like to add additional geoms to a ggplot density plot, but without changing the displayed limits of the data and without having to compute the desired limits by custom code. To give an example: set.seed(12345) N = 1000 d = data.frame(measured = ifelse(rbernoulli(N, 0.5), rpois(N, 100), rpois(N,1))) d$fit = dgeom(d$measured, 0.6) ggplot(d, aes(x = measured)) + geom_density() + geom_line(aes(y = fit), color = "blue") ggplot(d, aes(x = measured)) + geom_density() + geom_line(aes(y = fit)

Plotting one variable both line-only and points-only, depending on value

北城余情 提交于 2021-02-05 05:13:12
问题 I would like to use ggplot2 to plot 3 time series in the same graph. I'd like to plot the first 2 series as solid lines without points. And I would like to plot the third series with points only and no line. How can I do that? library(ggplot2) library(reshape2) d1 <- c(1, 2, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 1) d2 <- c(0, 2, 4, 5, 4, 3, 2, 4, 6, 7, 6, 5, 3, 1) d3 <- c(0, 1, 2, 4, 4, 2, 1, 3, 4, 7, 8, 3, 5, 0) ts1 <- ts(d1, c(2015, 01), c(2016, 03), frequency = 12) ts2 <- ts(d2, c(2015, 01), c

ggplot annotation in fixed place in the chart

岁酱吖の 提交于 2021-02-05 05:11:35
问题 I am plotting the following data into a ggplot bar chart. structure(list(MEDIATYPE = c("BACKLIT TOWER", "BILLBOARDS", "BRIDGE PANEL", "BUILDING FACADES", "BUS SHELTER", "CANTILIVERS", "CYCLE SHELTER", "FOB", "FREE STANDING PANEL", "GANTRIES"), RENTAL = c(197, 278363, 1423, 26, 35960, 6194, 70, 4845, 27, 9420)), .Names = c("MEDIATYPE", "RENTAL"), row.names = c(NA, 10L), class = "data.frame") I am using the following code to render the chart. It is working fine. However the problem is the yaxis

Plotting one variable both line-only and points-only, depending on value

我只是一个虾纸丫 提交于 2021-02-05 05:11:30
问题 I would like to use ggplot2 to plot 3 time series in the same graph. I'd like to plot the first 2 series as solid lines without points. And I would like to plot the third series with points only and no line. How can I do that? library(ggplot2) library(reshape2) d1 <- c(1, 2, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 1) d2 <- c(0, 2, 4, 5, 4, 3, 2, 4, 6, 7, 6, 5, 3, 1) d3 <- c(0, 1, 2, 4, 4, 2, 1, 3, 4, 7, 8, 3, 5, 0) ts1 <- ts(d1, c(2015, 01), c(2016, 03), frequency = 12) ts2 <- ts(d2, c(2015, 01), c

ggplot annotation in fixed place in the chart

别说谁变了你拦得住时间么 提交于 2021-02-05 05:01:46
问题 I am plotting the following data into a ggplot bar chart. structure(list(MEDIATYPE = c("BACKLIT TOWER", "BILLBOARDS", "BRIDGE PANEL", "BUILDING FACADES", "BUS SHELTER", "CANTILIVERS", "CYCLE SHELTER", "FOB", "FREE STANDING PANEL", "GANTRIES"), RENTAL = c(197, 278363, 1423, 26, 35960, 6194, 70, 4845, 27, 9420)), .Names = c("MEDIATYPE", "RENTAL"), row.names = c(NA, 10L), class = "data.frame") I am using the following code to render the chart. It is working fine. However the problem is the yaxis

How can I use stat_smooth to show one line, on a two factor figure?

£可爱£侵袭症+ 提交于 2021-02-05 05:01:02
问题 I have a data.frame as such: df <- data.frame(a = runif(1000), b = runif(1000), c = runif(1000), d = sample(c("yes", "no"), 1000, replace=TRUE)) And I ran a logistic regression: lm <- glm(data = df, factor(d) ~ a + b + c, family = binomial) Produced the predicted probabilities: df$pred <- predict(lm, type = "response") And would like to graph the result with both a jitter plot for a and b , a color fill for d and a smooth line (using geom_smooth) for simply the effect of a on d I've tried