Hi,
I am trying to plot my pca in ggplot and I've manage to get something (picture attached).
My question is, How do I spread the axis scales to make it look better. This is the worst ggplot that I've ever seen! Please help me fix it.
This is my code:
b <- ggplot(pca, aes(PC1, PC2, col = spp, shape = loc)) + geom_point(size = 3)
b <- b + scale_colour_manual(values = c("red", "blue", "green", "yellow", "brown","purple"))
b <- b + coord_equal() + theme_light()
b + xlab(paste0("PC1 (", signif(pve$pve[1], 3), "%)")) + ylab(paste0("PC2 (", signif(pve$pve[2], 3), "%)"))
image: https://ibb.co/XLp4hCk
P.S: I'm new to R and very eager to learn. I tried setting x and y lim (scale_x_continuous, expand_limits, coord_cartesian etc.)
UPDATE: Here are the first few lines of data, as per request;
structure(list(ind = c("IID", "\"$i\"", "filtered_seq1trimq10_LHA_EU21_1.final_snps_\"$i\"",
"filtered_seq1trimq10_Tur09_1.final_snps_\"$i\"", "filtered_seq1trimq10_LHA_EU20_1.final_snps_\"$i\"",
"filtered_seq1trimq10_LHA_AS201_1.final_snps_\"$i\""), PC1 = c("PC1",
"0.0915729", "0.0946641", "0.0633914", "0.0951517", "-0.235733"
), PC2 = c("PC2", "0.040677", "0.0470369", "-0.0144166", "0.0490094",
"0.100445"),
Can you add some of your data to the post using
dput(head(pca))
? It makes it easier for people to answer the question.Thank you for the tip. I updated my post :)
code
option) to present your post better. You can use backticks for inline code (`text` becomestext
), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.Thank you so much for the helpful tips. I hardly ever post anything, because I can find answers to most of my questions here already.
Your example data is incomplete. Please post complete example data. Change the the intervals on Y-axis as they are numbers. It is not clear what is on the x-axis. If they are numbers (as y-axis values), change the interval. Why is
ind
character vector has$i
in it?PC "numbers" are not numeric:
I think you imported the data header as the 1st row, which then turned all following numeric values into character. Please share the code you have used for data import.