I'm using a ggplot chart with geom_tile in RShiny. When I select a category with fewer y-axis elements, the tiles increase in height. I'd like to fix the tile height so that the chart height decreases when there are fewer y-axis elements, code below:
ggplot(selected_data(), aes(week, zone, fill= value, text=text)) +
scale_y_discrete(limits = unique(rev(selected_data()$zone))) +
geom_tile(aes(fill = value)) +
geom_text(aes(label = format(round_half_up(value,digits = 1), nsmall = 1)), size=4) +
labs(x="Week", y="") +
scale_x_discrete(position = "top") +
scale_fill_viridis(option = "viridis") +
theme_grey(base_size = 16) + labs(fill = "Rate per\n1,000 population") +
theme(legend.position = "top")
Related
Im using this code:
bp <- ggplot(data2, aes(x="", y=percentage, fill=pangolin_lineage)) + geom_bar(width = 2, stat = "identity",alpha = 1.2) +
#scale_fill_manual(values = getPalette(colourCount)) +
scale_fill_manual(values=cal6) + facet_grid(year ~ month, switch = "x", space = "free") + #facet_wrap(year ~ month, nrow=1, scales="free_x", strip.position = c("top"))
ylab("Percentage of sequences") + xlab(NULL) + #titulos
theme_minimal()+ scale_y_continuous(labels=scales::percent)+ theme(strip.text = element_text(size=18))
And I need year to be showed up while month is showed down. I wonder if there is a way to fix this a make it use the same percentage scale too. This is the plot I'm getting with this code ):
graph
I created a stacked bar chart using ggplot and the following code:
ggplot(group, aes(x = variable, y = value, fill = Taxa)) +
geom_bar(position = "fill", stat = "identity") +
scale_fill_manual(values = Cb64k) +
scale_y_continuous(labels = percent_format()) +
theme(legend.position = "bottom", text=element_text(size=10.5),
axis.text.x = element_text(angle=0, vjust=1)) +
guides(fill = guide_legend(ncol=6)) +
facet_grid(cols=vars(group), scales = "free_x", space = "free_x") +
ggtitle(opt$gtitle) +
xlab("Patient ID") + ylab("Relative Activity")
To get this output:
Is there a way to reorder the "stacks" in each bar so that the size of the stacks go from largest to smallest starting at the bottom? As you can see with the current output it seems to be random.
I want to create a plot with a single vertical bar (colored continuously), with a mark on it showing the score for a particular person. Image:
I can generate the colored bar in ggplot, but only as a legend (not the actual plot). For example the legend resulting from the following is fine:
ggplot(mtcars, aes(x=wt, y=mpg, color=mpg)) +
geom_point() +
scale_color_gradientn(colors = rainbow(5))
Is there any way to do this? Any help would be really appreciated - I'm completely stuck on this.
ggplot(data.frame(y = 51), aes( y=y)) +
geom_tile(data = data.frame(y = 0:100),
aes(x= 0.5, y = y, fill = y)) +
geom_segment(aes(x=0, xend=1, yend=y)) +
geom_text(aes(label = y, x = 1), hjust = -0.3) +
coord_cartesian(clip = "off", xlim = c(0,1.2)) +
scale_fill_gradientn(colors = rainbow(5)) +
scale_x_continuous(labels = NULL) +
guides(fill = FALSE) +
theme_minimal() +
theme(line = element_blank()) +
labs(x="", y = "")
I'm trying to great a plot with one legend on the right side and one on the bottom. Both outside the map. I have tried a few suggestions but either both legends or neither legend moves.
library(ggthemes)
library(ggmap)
library(ggplot2)
d <- data.frame(McMap)
County_Mayo_Map <- get_map("MAP", zoom=9)
p <- ggmap(County_Mayo_Map)
p <- p + geom_point(data=d, aes(lat, lon)) +
geom_point(stat = "identity") +
geom_point(data = d, aes(color = Name), size = 5) +
scale_shape_manual(values=df$x) +
geom_point(data = d, aes(shape = Town), size = 4) +
labs(caption = ("SPM 8-19-17")) +
labs(title = "Title", subtitle = "Subtitle") +
ylab("Latitude") +
xlab("Longitude") +
coord_fixed(ratio = 1/1) +
theme(legend.background = element_rect(
fill ="lemonchiffon",
colour = "black",
size =1)) +
theme_solarized()
Is it possible to change the width of the header in the facet plot?
Here is my code:
ggplot(matrix_cpm_spike_norm_iso.all, aes(miRNA,value)) +
geom_boxplot(aes(fill = Condition)) +
facet_grid(~Experiment, space = "free_y", scale="free") +
theme_bw(base_size=12) +
theme(axis.text.x = element_text(colour = "black",angle=90 )) +
labs(x="miRNA",y="Expression (log2 cpm)")