ggplot2

gganimate: data present only in some frames

我的梦境 提交于 2021-02-11 17:57:20
问题 I have a problem animating plots where data in some layers in present only in some of the frames. In the example below, I have a moving point that can be nicely animated along 9 frames. However, when I add another layer with a point present only in some of the frames, I get the following error: Error: time data must be the same class in all layers Example : require(data.table) require(ggplot2) require(gganimate) # 9 points along x=y; present at every time point dtP1 = data.table(x = 1:9, y =

What is the simplest way to control the y-axis when using sec.axis

自闭症网瘾萝莉.ら 提交于 2021-02-11 16:27:02
问题 I have reading all post about scaling the y-axis and in all of them there are some extra steps in order to control the y-axis limits when using sec.axis in ggplot. I have the following df. structure(list(day = c(1, 3, 5, 7, 9), mean = c(0.000452620431539136, 0.000244953967091816, 0.000409529176828165, 0.000621566432113383, 0.000975471413145951), sd = c(0.000145928952108396, 7.48403498938327e-05, 8.70694523628839e-05, 0.000265199022927143, 0.00076194983870935 ), group = c("pi", "pi", "pi", "pi

ggplot not properly displaying

て烟熏妆下的殇ゞ 提交于 2021-02-11 15:02:33
问题 I currently am trying to graph 2 columns in a data frame I created using ggplot I am graphing date vs. numeric value. I used dplyr library to create the dataframe: is_china <- confirmed_cases_worldwide %>% filter(country == "China", type=='confirmed') %>% mutate(cumu_cases = cumsum(cases)) I believe the reason is due to the y value being a result column of cumsum function, but am unsure The table looks something like this, the last column being the targeted y value: 2020-01-22 NA China 31

downloadButton to download multiple renderPlot reactive in shiny server

跟風遠走 提交于 2021-02-11 14:57:30
问题 I am creating a shiny application that displays several graphics. And I will like through a button download, download all graphs display I do the following: server = function(input, output) { df<-data.frame(q=c(1,3,5,7,9),w=c(2,4,6,8,10),z=c(1,2,3,4,5)) # output all plot output$p1 <- renderPlot({ ggplot(df,aes(x=q,y=w)) + geom_point() }) output$p2 <- renderPlot({ ggplot(df,aes(x=z,y=w))+geom_point() }) output$p3 <- renderPlot({ ggplot(df,aes(x=q,y=z))+geom_point() }) # Here is my function to

Population pyramid in ggplot

对着背影说爱祢 提交于 2021-02-11 14:53:29
问题 I've read a related post (Simpler population pyramid in ggplot2), but I have a slightly different setup which results in a messed-up pyramid. Make the test data frame: test <- data.frame(cbind(c(replicate(3,"population 1"), replicate(3,"population 2")),c("top","middle","bottom","top","middle","bottom"),c(70,25,5,82,13,3))) Fix the factor ordering: levels(test$X3) [1] "13" "25" "3" "5" "70" "82" test$X3 <- factor(test$X3, levels=c(70,25,5,82,13,3)) levels(test$X2) [1] "Bottom" "Middle" "Top"

Population pyramid in ggplot

对着背影说爱祢 提交于 2021-02-11 14:50:10
问题 I've read a related post (Simpler population pyramid in ggplot2), but I have a slightly different setup which results in a messed-up pyramid. Make the test data frame: test <- data.frame(cbind(c(replicate(3,"population 1"), replicate(3,"population 2")),c("top","middle","bottom","top","middle","bottom"),c(70,25,5,82,13,3))) Fix the factor ordering: levels(test$X3) [1] "13" "25" "3" "5" "70" "82" test$X3 <- factor(test$X3, levels=c(70,25,5,82,13,3)) levels(test$X2) [1] "Bottom" "Middle" "Top"

How to use italic in label_bquote for strip text lables

天大地大妈咪最大 提交于 2021-02-11 14:29:58
问题 There have been many proposed solutions to many slightly different problems, but none quite catches my specific problem. What I want is the following: I want to mix normal subfig labels (a, b, c, ...) with species names in italics . So far, I only want do this for four species, so I could live with a manual solution. But a custom function automatizing the process would be neat... E.g. the strip text of species a would be: a) Genus species Here is a reproducible example with the iris dataset:

How to prevent ggplotly from altering ggplot figure for colorblind

我是研究僧i 提交于 2021-02-11 14:27:51
问题 I'm trying to generate interactive grayscale heatmap using a plot generated by ggplot, I will provide colored examples of the code and images, here is the colored figure that I have: I tried these options: Option didnot work zmapp023ac + scale_fill_identity() %>% ggplotly(.) I get an error: Error in UseMethod("ggplotly", p): no applicable method for 'ggplotly' applied to an object of class "c('ScaleDiscreteIdentity', 'ScaleDiscrete', 'Scale', 'ggproto', 'gg')" Options worked but altered my

How can I make my dumbbell chart in correct descending order?

爱⌒轻易说出口 提交于 2021-02-11 14:26:40
问题 I made an dumbbell chart to show the difference of product sales among different time windows (e.g.weekday VS weekend), and wanted to select the 20 most distinguished products in an descending order. But it seems my order and selection doesn't work properly. Here is the data for dumbbell chart : >head(product_dumbbell) product_aisle daytime evening long medium short weekday weekend 1: candles 16 4 2 6 12 15 5 2: asian foods 115 25 23 29 88 90 50 3: baby accessories 7 3 0 0 10 7 3 4: baby body

How to make a plot in r with multiple lines using ggplot

早过忘川 提交于 2021-02-11 13:59:54
问题 I am trying to do a graph in r with 3 lines using ggplot, but the third line does not appear in the graph. I used the following code: us_idlpnts <- subset(unvoting, CountryName == "United States of America") rus_idlpnts <- subset(unvoting, CountryName == "Russia") mdn_idl_pnt <- summarize(unvoting, PctAgreeUS = median(PctAgreeUS, na.rm=T), PctAgreeRUSSIA = median(PctAgreeRUSSIA, na.rm=T), idealpoint = median(idealpoint, na.rm=T), Year = median(Year, na.rm= T)) ggplot(NULL, aes(Year,