I'm creating scatter-plots using 2 variables (Tarsus Lengths) for several species. However, i have already separated them by their gender. What I want to do is assign a color and/or shape to the whole variable/column. I checked the ggplot documentation, and while very useful, i couldn't find a way to do this. My code looks like this:
data<-read.csv("UpdatedScriptTarsos.csv", header=TRUE)
str(datos)
arbol<-read.nexus("TrueTree.nex")
str(data)
str(arbol)
str(datos)
x<-datos[,5]
names(x)<-datos[,1]
y<-setNames(datos[,3],datos[,1])
ggplot(datos, aes(x= Log10.Tarso.H, y = Log10.Tarso.M)) + geom_jitter() + labs(x = "Tarso Female", y = "Tarso Male", title = "Indep_C Tarso")
Is it possible to show the male and female values with different colors?, or should i edit my databases?
dput(datos) Output
structure(list(NameinHarveyDatadump = c("Agrior_micro_A13502",
"Agrior_murnus_K11848", "Anaire_flaviro_CU52375", "Anaire_parlus_A12192",
"Alectr_risora_K3430", "Campto_imber_UWB69443", "Casior_rufus_L37981",
"Cnemot_fustus_YPM137446", "Cnipod_supfus_L78843", "Colorh_partri_K11725",
"Contop_alblar_YPM139867", "Contop_cinreu_LSU66921", "Contop_coope_A17527",
"Contop_pernax_L38710", "Contop_sorlus_K4994", "Contop_viren_MVZ168655",
"Culici_cauuta_L15410", "Elaen_albcep_A2714", "Elaen_chisis_L26884",
"Elaen_gigas_L43022", "Elaen_mesleu_MPEGCMN13", "Elaen_paltan_K3955",
"Elaen_partri_L48581", "Elaen_spelis_L42601", "Elaen_strera_K9711",
"Empinax_alblar_L60923", "Empinax_alnor_A17507", "Empinax_diffi_A15581",
"Empinax_flaves_L46480", "Empinax_flaviven_L46790", "Empinax_fulfron_W112498",
"Empinax_hammo_L47262", "Empinax_minim_A17530", "Empinax_oberh_L48075",
"Empinax_occlis_W115396", "Empinax_trail_LSU141724", "Empinax_vircen_LSUMZ23595",
"Empinax_wrigh_L64538", "Empinom_aurcri_SP90097", "Empinom_varius_SP86338",
"Euscar_melryp_L12982", "Fluvic_albter_L38135", "Fluvic_nen_GCPE50",
"Fluvic_pica_SB14542", "Gubern_yetap_K95", "Hemit_nidip_F395437",
"Hirund_fernea_Y101003", "Hymeno_pertus_SB14701", "Inezia_inoata_L37759",
"Knipo_atemus_LSU6578", "Knipo_cyatri_S630514", "Knipo_hudso_L18865",
"Knipo_nigmus_MPEGDZ5162", "Knipo_strcep_L38892", "Lathro_euler_SB5766",
"Lathro_gritus_L66161", "Legatu_leupha_L29950", "Leptop_amacep_L31480",
"Lesson_oreas_LSU61378", "Lesson_rufa_A9938", "Machet_rixosa_L37884",
"Megary_pitgua_L18467", "Mionec_oleag_LSU60680", "Mionec_olieus_LSUMZ90443",
"Muspip_vetula_A315092", "Musaxi_albfro_LSU22576", "Musaxi_alblor_A12171",
"Musaxi_alpin_L30037", "Musaxi_captus_A12128", "Musaxi_cinreu_A12179",
"Musaxi_flavcha_A12184", "Musaxi_griseus_K17552", "Musaxi_junin_L1203",
"Musaxi_maclo_K11679", "Musaxi_mactri_L103850", "Musaxi_rufver_L7728",
"Myiar_cincen_L5318", "Myiar_crini_L53031", "Myiar_nuttin_CZ335354",
"Myiar_swaoni_L48574", "Myiar_tuber_LSUMZ44174", "Myiar_tyrlus_LSU22558",
"Myiodyn_lutei_L28865", "Myiodyn_mactus_LSUMZ66057", "Myiopag_canic_L6656",
"Myiopag_gaim_L22839", "Myiopag_virata_LSU18455", "Myiopho_cryxan_LSU5964",
"Myiopho_fastus_GCN1412", "Myiorn_atrpil_LSUMZ30018", "Myioze_simi_L10837",
"Neoxol_ruftri_L70016", "Onych_cortus_L16286", "Phaeo_murina_L48589",
"Phymyi_burme_SP92440", "Phymyi_fastus_SP93548", "Pitang_sultus_L7348",
"Poeci_rufcep_H36", "Polyst_peclis_YPM137548", "Pseucol_acuti_L37915",
"Pseucol_flaviven_MPEGCMN37", "Pseucol_scleri_L38161", "Pyroce_rubnus_LSUMZ37157",
"Satrapa_icter_K9896", "Sayorn_nigcan_W90854", "Sayorn_phoebe_A6230",
"Sayorn_saya_L57523", "Serpop_cinrea_L22901", "Serpop_grilla_MZU86172",
"Serpop_nigcan_SB13623", "Serpop_subata_Y101031", "Siryst_sibtor_G258",
"Stigma_bud_L31591", "Subleg_modtus_L15283", "Suiriri_affin_MZUSP79714",
"Tachur_rubstr_S614701", "Tyranus_alblar_L15257", "Tyranus_caudif_L16814",
"Tyranus_couchi_L48091", "Tyranus_crassi_F343264", "Tyranus_domsis_L11353",
"Tyranus_forfic_L48080", "Tyranus_melcus_LSUMZ28429", "Tyranus_nivgul_L5241",
"Tyranus_savana_L48429", "Tyranus_tyrnus_L3328", "Tyranus_vertic_L41824",
"Tyranus_vocran_L58274", "Xolmis_cinreu_SB14699", "Xolmis_cortus_KU11859",
"Xolmis_irupe_SB14801", "Xolmis_pyrope_A12144", "Xolmis_rubtra_K11946",
"Xolmis_veltus_L38195"), Tarso.M = c(34.3, 27.4, 18.6, 18.6,
23.9, 13.9, 20.2, 18.3, 21.9, 17.7, 11, 13.13, 14.86, 16.3, 13.03,
13.875, 16.3, 19.4, 17.1, 19.2, 15.9, 17.5, 19.4, 19.9, 16.5,
16.2, 16.55, 17.08, 16.35, 15.6, 14.26, 15.41, 18.69, 17.45,
24.68, 16.46, 15, 18.075, 14.6, 15.5, 19.5, 20.8, 20.9, 20.2,
29, 19, 13.6, 27.4, 15.8, 23.7, 18.5, 20.4, 24.1, 19.6, 14.5,
15, 15.4, 15.31, 22, 22.2, 31.5, 19.1, 15.28, 16.96, 19.4, 37.5,
30.4, 31.4, 28.2, 28.9, 32.3, 32.5, 28.1, 28.8, 25.3, 28.5, 22.8,
20.4, 19.8, 20.7, 19.6, 21.6, 19.416, 19.4, 16.7, 17.72, 17.67,
14.6, 12.82, 15.95, 18.5, 36.5, 16.8, 17.2, 15.2, 14.6, 25.1,
16.6, 15.4, 18.4, 18.7, 16.3, 16.023, 18.8, 17.59, 19.49, 20.388,
16.33, 16.2, 18.6, 17.3, 19.4, 18.7, 15.5, 21.2, 18.7, 16.7,
22.1, 19.9, 19.8, 18, 18.7, 17.2, 17.5, 17.3, 18.5, 18.1, 19.5,
29.6, 29.5, 24.3, 27.9, 29.1, 25.6), Log10.Tarso.M = c(1.53529412004277,
1.43775056282039, 1.26951294421792, 1.26951294421792, 1.37839790094814,
1.1430148002541, 1.30535136944662, 1.26245108973043, 1.34044411484012,
1.24797326636181, 1.04139268515823, 1.11826472608948, 1.17201880942456,
1.21218760440396, 1.11494441571258, 1.14223299179471, 1.21218760440396,
1.28780172993023, 1.23299611039215, 1.28330122870355, 1.20139712432045,
1.24303804868629, 1.28780172993023, 1.29885307640971, 1.21748394421391,
1.20951501454263, 1.21879799811174, 1.23248786635299, 1.21351775699631,
1.19312459835446, 1.15411952551585, 1.18790971954814, 1.27160930137883,
1.2417954312952, 1.3923451553612, 1.21642983087625, 1.17609125905568,
1.25707830596657, 1.16435285578444, 1.19033169817029, 1.29003461136252,
1.31806333496276, 1.32014628611105, 1.30535136944662, 1.46239799789896,
1.27875360095283, 1.13353890837022, 1.43775056282039, 1.19865708695442,
1.3747483460101, 1.26717172840301, 1.3096301674259, 1.38201704257487,
1.29225607135648, 1.16136800223497, 1.17609125905568, 1.18752072083646,
1.18497519069826, 1.34242268082221, 1.34635297445064, 1.4983105537896,
1.28103336724773, 1.18412335423967, 1.2294258479207, 1.28780172993023,
1.57403126772772, 1.48287358360875, 1.49692964807321, 1.45024910831936,
1.46089784275655, 1.5092025223311, 1.51188336097887, 1.44870631990508,
1.45939248775923, 1.40312052117582, 1.45484486000851, 1.35793484700045,
1.3096301674259, 1.29666519026153, 1.31597034545692, 1.29225607135648,
1.33445375115093, 1.28815976332388, 1.28780172993023, 1.22271647114758,
1.24846371755103, 1.24723654950676, 1.16435285578444, 1.1078880251828,
1.2027606873932, 1.26717172840301, 1.56229286445647, 1.22530928172586,
1.23552844690755, 1.18184358794477, 1.16435285578444, 1.39967372148104,
1.22010808804006, 1.18752072083646, 1.26481782300954, 1.2718416065365,
1.21218760440396, 1.2047438326888, 1.27415784926368, 1.24526583945746,
1.28981183911762, 1.30937462491667, 1.21298618473667, 1.20951501454263,
1.26951294421792, 1.2380461031288, 1.28780172993023, 1.2718416065365,
1.19033169817029, 1.32633586092875, 1.2718416065365, 1.22271647114758,
1.34439227368511, 1.29885307640971, 1.29666519026153, 1.25527250510331,
1.2718416065365, 1.23552844690755, 1.24303804868629, 1.2380461031288,
1.26717172840301, 1.25767857486918, 1.29003461136252, 1.47129171105894,
1.46982201597816, 1.38560627359831, 1.4456042032736, 1.46389298898591,
1.40823996531185), Tarso.H = c(33.5, 27.5, 17.1, 18.2, 22.5,
14.1, 20.8, 17.7, 21.8, 17.2, 9.8, 13.25, 14.8, 17.03, 12.81,
12.45, 15, 18.2, 16.9, 19.6, 17, 17.2, 17.9, 18.7, 15.8, 16.5,
16.1293, 17.12, 15.9, 16.1, 14.02, 15.0013, 18.07, 17.13, 23.86,
16.58, 15.4, 17.8516, 14.9, 15.8, 18.1, 20.3, 21.7, 20.3, 28.2,
18.5, 14.6, 26.8, 15, 22.8, 19.6, 19.8, 22.7, 19.7, 14.5, 15,
15.1, 14.73, 21.7, 21.7, 26.5, 18.9, 12.14, 16.36, 20.6, 37.4,
30.1, 30.6, 28.4, 28.4, 31, 32.1, 27.5, 29.4, 25.8, 28.5, 22.1,
20.1, 17.6, 20.1, 19, 22.1, 19.484, 20.1, 15.675, 16.81, 17.74,
14.9, 12.9, 15.75, 19.4, 35.7, 15.93, 18, 15.4, 15.7, 25.4, 17.2,
15.7, 18.1, 18.2, 17.9, 16.4, 19, 17.1294, 19.45, 19.65, 16.192,
16.8, 17.1, 16.5, 19.1, 19.4, 13.8, 20, 18, 19, 22.17, 19, 19.6,
19.2, 18.3, 17.5, 17.7, 17.9, 18.5, 18.6, 19.5, 28.7, 28.5, 23.1,
26.5, 30.1, 28), Log10.Tarso.H = c(1.52504480703685, 1.43933269383026,
1.23299611039215, 1.26007138798507, 1.35218251811136, 1.14921911265538,
1.31806333496276, 1.24797326636181, 1.3384564936046, 1.23552844690755,
0.991226075692495, 1.12221587827283, 1.17026171539496, 1.2312146479626,
1.10754912974469, 1.09516935143176, 1.17609125905568, 1.26007138798507,
1.22788670461367, 1.29225607135648, 1.23044892137827, 1.23552844690755,
1.25285303097989, 1.2718416065365, 1.19865708695442, 1.21748394421391,
1.20761551973031, 1.23350376034113, 1.20139712432045, 1.20682587603185,
1.14674801363064, 1.17612889627986, 1.25695815256093, 1.23375736296551,
1.37767043933432, 1.21958452621425, 1.18752072083646, 1.25167714706055,
1.17318626841227, 1.19865708695442, 1.25767857486918, 1.30749603791321,
1.33645973384853, 1.30749603791321, 1.45024910831936, 1.26717172840301,
1.16435285578444, 1.42813479402879, 1.17609125905568, 1.35793484700045,
1.29225607135648, 1.29666519026153, 1.35602585719312, 1.29446622616159,
1.16136800223497, 1.17609125905568, 1.17897694729317, 1.16820274684263,
1.33645973384853, 1.33645973384853, 1.42324587393681, 1.27646180417324,
1.08421868673924, 1.2137832993353, 1.31386722036915, 1.57287160220048,
1.47856649559384, 1.48572142648158, 1.45331834004704, 1.45331834004704,
1.49136169383427, 1.50650503240487, 1.43933269383026, 1.46834733041216,
1.41161970596323, 1.45484486000851, 1.34439227368511, 1.30319605742049,
1.24551266781415, 1.30319605742049, 1.27875360095283, 1.34439227368511,
1.28967812089973, 1.30319605742049, 1.19520754950275, 1.22556771343947,
1.24895361549571, 1.17318626841227, 1.11058971029925, 1.19728055812562,
1.28780172993023, 1.55266821611219, 1.20221577580113, 1.25527250510331,
1.18752072083646, 1.19589965240923, 1.40483371661994, 1.23552844690755,
1.19589965240923, 1.25767857486918, 1.26007138798507, 1.25285303097989,
1.2148438480477, 1.27875360095283, 1.23374215098345, 1.28891960566173,
1.29336255471145, 1.20930049515971, 1.22530928172586, 1.23299611039215,
1.21748394421391, 1.28103336724773, 1.28780172993023, 1.13987908640124,
1.30102999566398, 1.25527250510331, 1.27875360095283, 1.34576569311449,
1.27875360095283, 1.29225607135648, 1.28330122870355, 1.26245108973043,
1.24303804868629, 1.24797326636181, 1.25285303097989, 1.26717172840301,
1.26951294421792, 1.29003461136252, 1.45788189673399, 1.45484486000851,
1.36361197989214, 1.42324587393681, 1.47856649559384, 1.44715803134222
)), class = "data.frame", row.names = c(NA, -134L))
Ok, after clarification I think you need this:
library(dplyr)
library(ggplot2)
library(tidyr)
df %>%
pivot_longer(starts_with("log")) %>%
ggplot(aes(x = NameinHarveyDatadump, y = value, color = name)) +
geom_point(size = 3)+
scale_color_manual(values = c(Log10.Tarso.M="red", Log10.Tarso.H="blue"))+
theme_classic()+
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
I case you don't need the x axis labels then we could do:
library(dplyr)
library(ggplot2)
library(tidyr)
df %>%
pivot_longer(starts_with("log")) %>%
ggplot(aes(x = NameinHarveyDatadump, y = value, color = name)) +
geom_point(size = 3)+
scale_color_manual(values = c(Log10.Tarso.M="red", Log10.Tarso.H="blue"))+
theme_minimal()+
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())
First answer: Assuming .H and .M mark the gender. One way is to subest the df:
library(ggplot2)
ggplot() +
geom_jitter(data = df, aes(x = Log10.Tarso.M, y = Log10.Tarso.H), color = "red") +
geom_jitter(data = df, aes(x = Log10.Tarso.H, y = Log10.Tarso.M), color = "blue") +
labs(title = "Scatter plot of Log10.Tarso.M vs Log10.Tarso.H",
x = "Log10.Tarso", y = "Log10.Tarso") +
theme_minimal() +
theme(legend.position = "none")