ggplot2

Convert YYYY-MM-DD to YYYY-YY Qx in R

て烟熏妆下的殇ゞ 提交于 2021-02-19 07:39:20
问题 I'm trying to plot data by quarter then display in ggplot. Dates in dataset are of the format YYYY-MM-DD, and I want the ggplot x-axis to display the financial year like YYYY-YY Qx. The financial year starts July 1. Data is in long format. This is where I've got to: Data set named: TOX TREE_ID PM_Date variable value 1: 2013000584 2013-04-02 elm 0 2: 2013000498 2013-06-11 elm 1 3: 2013000123 2013-09-03 maple 0 4: 2013000642 2014-02-15 maple 0 5: 2013000778 2016-07-08 maple 1 PM_Dateq <- as

How do you set the color palette so that it starts with the darkest color, where older data being lighter than current

本小妞迷上赌 提交于 2021-02-19 07:37:27
问题 I'm plotting a correlation scatter plot, where my data frame has time data and the start year is arbitrary. In this case now I have the following R code ## Set seed for randomness in dummy data: ## set.seed(123) ## Create data frame: ## df.Data <- data.frame(date = seq(as.Date('2019-01-01'), by = '1 day', length.out = 650), DE = rnorm(650, 2, 1), AT = rnorm(650, 5, 2)) corPearson <- cor.test(x = df.Data$DE, y = df.Data$AT, method = "pearson") df.Data$year <- format(as.Date(df.Data$date), '%Y'

scale_colour_gradient vs. scale_fill_gradient in ggplot2

柔情痞子 提交于 2021-02-19 07:18:07
问题 I am an absolute beginner in ggplot2 and trying to draw beautiful figures using this package. I am going through the manual and I didn't understand the difference between scale_colour_gradient() vs. scale_fill_gradient() In my analysis, I will use "hypothesis" for observations because I am unsure about my conclusions. Here's the original code that worked for me: Experiment 1 erupt <- ggplot(faithfuld, aes(waiting, eruptions, fill = density)) + geom_raster() erupt Hypothesis: It plots the

Colorbar guide with string labels

余生颓废 提交于 2021-02-19 05:52:15
问题 I would like to modify the guide_colorbar of a continuous aesthetic with character descriptions, e.g., 'low' and 'high', instead of actual numbers. This can be especially useful when using one legend or colorbar for multiple plots (heatmaps, e.g, geom_bin2d ). Here an example. Say given dummy data: dd <- data.frame(xx=rnorm(100),yy=rnorm(100),zz=rep(1:10,10)) I can do the usual ggplot(dd,aes(xx,yy,color=zz))+ geom_point()+ viridis::scale_color_viridis(option='A',direction=-1) and hide

Flow duration curve using facet_wrap of ggplot in R?

混江龙づ霸主 提交于 2021-02-19 05:27:05
问题 I am using fdc of hydroTSM package . I have three data.frame and i would like to construct Flow duration curves (FDC) of the data.frame using facet_wrap functionality of ggplot to have the plots in three rows and one column . the following will produce FDC curves for DF1 . library(tidyverse) library(hydroTSM) library(gridExtra) DF1 = data.frame(Ob = runif(1000,0,500), A = runif(1000,0,700), B = runif(1000,2,800)) DF2 = data.frame(Ob = runif(1000,0,500), A = runif(1000,0,700), B = runif(1000,2

Flow duration curve using facet_wrap of ggplot in R?

早过忘川 提交于 2021-02-19 05:26:37
问题 I am using fdc of hydroTSM package . I have three data.frame and i would like to construct Flow duration curves (FDC) of the data.frame using facet_wrap functionality of ggplot to have the plots in three rows and one column . the following will produce FDC curves for DF1 . library(tidyverse) library(hydroTSM) library(gridExtra) DF1 = data.frame(Ob = runif(1000,0,500), A = runif(1000,0,700), B = runif(1000,2,800)) DF2 = data.frame(Ob = runif(1000,0,500), A = runif(1000,0,700), B = runif(1000,2

Highlight / Draw a box around some of the plots when using `facet_grid` in ggplot2

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-19 05:01:32
问题 I am creating a matrix of plots similar to ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_grid(rows = vars(cyl), cols = vars(drv)) Now, I would like to have some way to highlight some of the individual plots, say the ones where cyl is 5 or 6, and drv is f . So, ideally, this might look like this: But I would also be happy with those panels having a different look by setting ggtheme to classic or similar. However, it is very unclear to me how I can modify individually selected plots

R - How to create a seasonal plot - Different lines for years

ⅰ亾dé卋堺 提交于 2021-02-19 03:50:10
问题 I already asked the same question yesterday, but I didnt get any suggestions until now, so I decided to delete the old one and ask again, giving additional infos. So here again: I have a dataframe like this: Link to the original dataframe: https://megastore.uni-augsburg.de/get/JVu_V51GvQ/ Date DENI011 1 1993-01-01 9.946 2 1993-01-02 13.663 3 1993-01-03 6.502 4 1993-01-04 6.031 5 1993-01-05 15.241 6 1993-01-06 6.561 .... .... 6569 2010-12-26 44.113 6570 2010-12-27 34.764 6571 2010-12-28 51.659

Different fill orders in geom_bar per discrete x-value

十年热恋 提交于 2021-02-19 02:57:25
问题 I have this ggplot: What I want to do is change the order of cat2 in each distinct cat1 -category in decreasing order of share : For cat1 == Z: i would come first, because it has the largest share in that cat1 , followed by k , then j etc. For cat1 == Y: j would come first, because it has the largest share in that cat1 , followed by h , k , f , g and so on for all cat1-categories. I know I can control the order by defining factor levels, but since I need a different order in different cat1

r combine ggRadar and facet_wrap

久未见 提交于 2021-02-19 02:36:29
问题 The code below illustrates my question. I want to use the ggRadar function in ggiraphExtra because it allows interaction with the graph. I want a separate spider graph for each nutrient and I want each spider graph to have a separate set of connected dots for each year. As I understand things now, in ggRadar, the code mapping = aes(colour = year) is what gives separate dots for each year. in facet_wrap the code facet_wrap(~ nutrient) is what determines how many separate spider graphs there