Hello,
I am a very beginner in R.
I want to create a plot with individuals A, B and C in y, position in x (it's a position not a value, so I don't want a proportional representation on the graph). Each individual has value 0, 1 or 2 for each position.
I tried to draw a mosaic plot in R-studio but I received an error message:
"Aesthetics must be either length 1 or the same as the data (62): y, fill"
library(ggplot2)
example <- read.csv("EXAMPLE.csv", header = TRUE, sep=";")
ggplot(data = example, mapping = aes(x = position, y = factor(c("A", "B", "C")), fill = c("0","1","2"))) +
geom_tile() +
scale_fill_manual(
name = NULL,
breaks = c(0, 1, 2),
labels = c("0: NC", "1: M", "2: S"),
values = c("grey", "red", "green")
)+
scale_x_discrete(expand = c(0, 0)) +
scale_y_discrete(expand = c(0, 0)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
labs(
x = "Position ...",
y = NULL,
title = "Test ..."
)!
Can you help me, please?
Please find attached, the result that I want to get and the data.
Many thanks for your answers!