Posts

Showing posts with the label ggplot2

How do you specifically order ggplot2 x axis instead of alphabetical order?

Image
How do you specifically order ggplot2 x axis instead of alphabetical order? I'm trying to make a heatmap using ggplot2 using the geom_tiles function here is my code below: heatmap ggplot2 geom_tiles p<-ggplot(data,aes(Treatment,organisms))+geom_tile(aes(fill=S))+ scale_fill_gradient(low = "black",high = "red") + scale_x_discrete(expand = c(0, 0)) + scale_y_discrete(expand = c(0, 0)) + theme(legend.position = "right", axis.ticks = element_blank(), axis.text.x = element_text(size = base_size, angle = 90, hjust = 0, colour = "black"), axis.text.y = element_text(size = base_size, hjust = 1, colour = "black")). data is my data.csv file my X axis is types of Treatment my Y axis is types of organisms I'm not too familiar with commands and programming and I'm relatively new at this. I just want to be able to specify the order of the labels on the x axis. In this case, I'm trying to specify the order of...

Displaying stat_summary within each group, by aesthetic mapping, in ggplot

Image
Displaying stat_summary within each group, by aesthetic mapping, in ggplot I am close to plotting what I wanted, but haven't quite figured out whether stat_summary is the right way to display the desired plot. stat_summary The desired output is the scatter plot with a median line for each year, within each category. For example, in the plot below, I would want a median line for the values in 1999, 2000, and 2001 in Category A (i.e., 3 lines by color) and then the same in Category B (so 6 median lines total). I looked here, but this didn't seem to get at what I wanted since it was using facets. My plot looks like it is drawing a line between the medians of each category. Can stat_summary just draw a median line within each category, or do I need to use a different approach (like calculating the medians and adding each line to the plot by category? stat_summary Reproducible simple example library(tidyverse) library(lubridate) # Sample data Date <- sort(sample(seq(a...