case_when in mutate pipe

As of version 0.7.0 of dplyr, case_when works within mutate as follows: For more information: http://dplyr.tidyverse.org/reference/case_when.html

Categories R

Extracting value specific rows in R

Assuming that your data is in a data frame called mydata, you can select the rows you want by writing It might be easier to understand by doing it in multiple steps:

Categories R

Editing legend (text) labels in ggplot

The tutorial @Henrik mentioned is an excellent resource for learning how to create plots with the ggplot2 package. An example with your data: this results in: As mentioned by @user2739472 in the comments: If you only want to change the legend text labels and not the colours from ggplot’s default palette, you can use scale_color_hue(labels = c(“T999”, “T888”)) instead … Read more

Error in plot.window(…) : need finite ‘xlim’ values

The problem is that you’re (probably) trying to plot a vector that consists exclusively of missing (NA) values. Here’s an example: In your example this means that in your line plot(costs,pseudor2,type=”l”), costs is completely NA. You have to figure out why this is, but that’s the explanation of your error. From comments: Scott C Wilson: Another possible cause of … Read more

SummarySE (Rmisc package) to produce a barplot with error bars (ggplot2)

Both the code variants that you posted won’t work because they are using the function summarySE() wrongly: Version 1: You use Family as the measurement variable, which means that you ask the function to give you mean, standard deviation, etc. of Family. Version2: You correctly group by Family, but now you supply many measurement variables. This does not work because summarySE() expects a … Read more

Categories R Tags