Create scree plot with primary and secondary y axis in R

Advertisements I have a dataset structure(list(X = c(26.7788998092606, 18.6280163936587, 14.349845629237, 9.66310505252417, 7.94423462318618, 5.04943860391983, 3.27216212415563, 2.94046432374716, 2.16429582651011, 1.63761158654806, 1.11240348866093 ), X0 = 1:11, index1 = c(26.7788998092606, 18.6280163936587, 14.349845629237, 9.66310505252417, 7.94423462318618, 5.04943860391983, 3.27216212415563, 2.94046432374716, 2.16429582651011, 1.63761158654806, 1.11240348866093), variance_pct = c(28.6281410315749, 19.9143909665674, 15.3407872385057, 10.3303995390774, 8.49283095274311, 5.39813216797301, 3.49812424840959, 3.14352075545081, 2.31375323843416, 1.75069834043094, 1.18922152083292), cumulative_variance = c(28.6281410315749, 48.5425319981423, 63.883319236648, 74.2137187757255, 82.7065497284686,… Read More Create scree plot with primary and secondary y axis in R

Geom points change position when changing color

Advertisements I have a plot with multiple elements, see below: The code for this is df2 <- data %>% group_by(presence,class,Wolf) %>% summarise(roaddensity_mean=mean(roaddens),dens_se_group=standard_error(roaddens)) df3 <- df2 %>% group_by(presence,class) %>% summarise(roaddensity_mean=mean(roaddensity_mean),dens_se_group=mean(dens_se_group)) p1 <- ggplot(df1,aes(x=class,y=roaddensity_mean,color=presence)) + geom_errorbar(data=df3,aes(ymin=roaddensity_mean-1.96*dens_se_group, ymax=roaddensity_mean+1.96*dens_se_group,color=presence), width = 0.4,size=1,position=position_dodge(width=0.5))+ labs(title=”,y="Road density/km²",x="") + geom_point(data=df2,stat=’identity’,position=position_dodge(width=0.5),size=1.25,alpha=0.4) + ylim(0,2) + scale_color_manual(values=c("#40B0A6","#E1BE6A"))+ theme(axis.text.x=element_blank(),legend.direction = "horizontal",plot.margin = unit(c(0.35, 0.5, 0, 0.5), "cm"),… Read More Geom points change position when changing color

Hide '0' values (zero counts) in plots utilizing geom_count

Advertisements I use geom_count() from the ggplot2 library to overlay the count (blue) on top of the total number (gray) for each dataset split by weeks (see example dataset and plot below). Sometimes, the count value is ‘0’ (here: in DS1, week 3). # sample dataset set.seed(1) df = data.frame(dataset = paste0("DS",rep(1:4, each = 5)),… Read More Hide '0' values (zero counts) in plots utilizing geom_count

Hide '0' values (zero counts) in plots utilizing geom_count

Advertisements I use geom_count() from the ggplot2 library to overlay the count (blue) on top of the total number (gray) for each dataset split by weeks (see example dataset and plot below). Sometimes, the count value is ‘0’ (here: in DS1, week 3). # sample dataset set.seed(1) df = data.frame(dataset = paste0("DS",rep(1:4, each = 5)),… Read More Hide '0' values (zero counts) in plots utilizing geom_count

How to add split lines to the scatter plot to divide the scatter points into Top K

Advertisements For df, it is assumed that the values of price_index and quantity_index have co-consistency. products price_index quantity_index price_rank quantity_rank 1 a 95.00000 95.00000 high_price high_volume 2 b 80.69012 94.53585 high_price high_volume 3 c 74.41048 90.95081 high_price high_volume 4 d 73.24853 89.82692 medium_price medium_volume 5 e 70.50442 79.71225 medium_price medium_volume 6 f 67.11609 75.43498 low_price… Read More How to add split lines to the scatter plot to divide the scatter points into Top K

Control alpha on geom_rect with facet_wrap

Advertisements I am trying to get partially transparent rectangles on a faceted plot. The following illustrates what I’m trying to do, except that the alpha argument isn’t working: library(dplyr) library(ggplot2) df <- iris %>% filter(Species == "setosa" | Species == "versicolor") %>% group_by(Species) %>% mutate(plq = cut(Petal.Length, quantile(Petal.Length, probs = seq(0, 1, 0.5)), labels =… Read More Control alpha on geom_rect with facet_wrap