thanks a lot for your help! It does work, i tried it with xlim(1,250000) if you can also try it, i dont understand why the line from 250.000 to 100.000 which is mus musculus is green but the color for mus musculus on the color legened on the right is blue (?)
ggplot2 problem many variables
First of, sorry if i dont explain this the right way. I am R-studio noobie and i am trying to plot this data shown below, but no success. I want for example in x-axis to show the hits column, the y-axis to show the clusters column and to seperate these via color from species column. For example i also included what i wrote in R studio but i am guessing its totally wrong. Thanks in advance
ggplot(mydata, aes(x=hits, y = clusters,group = 1, colour = species)) +
geom_point() +
xlim(1000,100000) +
geom_line()
clusters hits species
2 or more 100000 homo sapiens
3 or more 29411 homo sapiens
4 or more 14998 homo sapiens
5 or more 8655 homo sapiens
2 or more 250000 mus musculus
3 or more 100000 mus musculus
4 or more 56088 mus musculus
5 or more 32181 mus musculus
2 or more 100000 chimp
3 or more 30783 chimp
4 or more 14760 chimp
5 or more 8063 chimp
2 or more 2149 drosophila
3 or more 173 drosophila
4 or more 39 drosophila
5 or more 23 drosophila
2 or more 26402 Zebrafish
3 or more 7462 Zebrafish
4 or more 3557 Zebrafish
5 or more 2122 Zebrafish
2 or more 2757 C elegans
3 or more 409 C elegans
4 or more 115 C elegans
5 or more 56 C elegans
2 or more 243 Cerevisiae
3 or more 29 Cerevisiae
4 or more 8 Cerevisiae
5 or more 4 Cerevisiae
2 or more 25066 Zea mays
3 or more 2921 Zea mays
4 or more 940 Zea mays
5 or more 581 Zea mays
2 or more 3551 Arabidopsis thaliana
3 or more 482 Arabidopsis thaliana
4 or more 122 Arabidopsis thaliana
5 or more 43 Arabidopsis thaliana
• 1,378 views
•
link
1 answer
I don't understand what you're trying to accomplish with the geom_line(), but your code works fine for me:
bdat <- read.table(sep="\t", quote="", stringsAsFactors = FALSE, header = TRUE, text = "clusters hits species
2 or more 100000 homo sapiens
3 or more 29411 homo sapiens
4 or more 14998 homo sapiens
5 or more 8655 homo sapiens
2 or more 250000 mus musculus
3 or more 100000 mus musculus
4 or more 56088 mus musculus
5 or more 32181 mus musculus
2 or more 100000 chimp
3 or more 30783 chimp
4 or more 14760 chimp
5 or more 8063 chimp
2 or more 2149 drosophila
3 or more 173 drosophila
4 or more 39 drosophila
5 or more 23 drosophila
2 or more 26402 Zebrafish
3 or more 7462 Zebrafish
4 or more 3557 Zebrafish
5 or more 2122 Zebrafish
2 or more 2757 C elegans
3 or more 409 C elegans
4 or more 115 C elegans
5 or more 56 C elegans
2 or more 243 Cerevisiae
3 or more 29 Cerevisiae
4 or more 8 Cerevisiae
5 or more 4 Cerevisiae
2 or more 25066 Zea mays
3 or more 2921 Zea mays
4 or more 940 Zea mays
5 or more 581 Zea mays
2 or more 3551 Arabidopsis thaliana
3 or more 482 Arabidopsis thaliana
4 or more 122 Arabidopsis thaliana
5 or more 43 Arabidopsis thaliana
")
ggplot(bdat, aes(x=hits, y = clusters,group = 1, colour = species)) + geom_point() + xlim(1000, 100000)
Warning message:
Removed 16 rows containing missing values (geom_point).

## Remove all data points <1000 and >100000 as they're not being plotted anyway
ggplot(bdat[bdat$hits>=1000 & bdat$hits<=100000,], aes(x=hits, y = clusters,group = 1, colour = species)) + geom_point() + xlim(1000, 100000) + geom_line()

• 0 views
•
link
• 0 views
•
link
Log in to answer this question.
I guess you'll have to remove the
or morefrom clusters