Fixing the use of a regression line with a linear model in ggplot

40 Views Asked by At

As part of my research i'm trying to generate some scatter-plots with Independent contrast analysis. While I got the graphs working, i am unable to get the regression line to show. If possible, i would like for this line to show as dotted. This is my current code:

library(phytools)
library(ape)
library(tidyverse)

datos<-read.csv("UpdatedScriptBeakDepth.csv", header=TRUE)
str(datos)
arbol<-read.nexus("TrueTree.nex")

###Clipping my phylogenetic tree in order to work with targe species

arbol$tip.label[which((arbol$tip.label %in% datos$NameinHarveyDatadump)==FALSE)]
as.character(datos$NameinHarveyDatadump)[which((as.character(datos$NameinHarveyDatadump) %in%          arbol$tip.label)==FALSE)]

tip.label[which((arbol$tip.label %in% datos$NameinHarveyDatadump)==FALSE)]
arbol.cortado<-drop.tip(arbol, sp.drop)
arbol.cortado$tip.label[which((arbol$tip.label %in% datos$NameinHarveyDatadump)==FALSE)]


###Independent contrast 

icx<-pic(x,arbol.cortado)
icy<-pic(y,arbol.cortado)

str(icx)
icx
str(icy)
icy

length(icx) <- length(x)
length(icy) <- length(y)

datos_updated = cbind(datos,icx,icy)

ggplot() +
    geom_point(datos=datos_updated, mapping=aes(x = icx, y = icy), color = "cornflowerblue") +
      geom_point(datos=datos_updated, mapping=aes(x = icy, y = icx), color = "deeppink") +
      geom_smooth(method='lm', se=FALSE) +
      labs(title = "Indep_Contrasts Beak Depth", 
       x = "BD Female", y = "BD Male") +
      theme_minimal() +
      theme(legend.position = "none")

enter image description here

I get the next output in the previous lines:

Warning messages: 1: In geom_point(datos = datos_updated, mapping = aes(x = icx, y = icy), : Ignoring unknown parameters: datos 2: In geom_point(datos = datos_updated, mapping = aes(x = icy, y = icx), : Ignoring unknown parameters: datos 3: Removed 1 rows containing missing values (geom_point()). 4: Removed 1 rows containing missing values (geom_point()).

While i get no error regarding the use of geom_smooth, it does not show in the graphs that I make. Any help would be appreciated. Thank you.

#dput(datos) Output

dput(datos)
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"), Profundidad.pico.M = c(7.3, 4.1, 3.2, 
2.1, 4.7, 3.1, 5.2, 4.1, 7.5, 2.8, 3.4, 3.6, 6.5, 5.6, 9.08, 
4.1124, 3.1, 3.6, 4, 4.4, 3.4, 3.6, 3, 4.2, 3.5, 3.3, 8.24, 7.59, 
8.7, 3.5, 7.33, 3, 3.2, 8, 7.67, 8.9, 3.8, 9, 4.7, 5.3, 2.9, 
3.5, 4, 3.3, 8.8, 2.8, 4.8, 4.5, 2.4, 4.8, 4.3, 4, 5.1, 3.3, 
4, 3.6, 4.2, 9.3526, 2.8, 2.5, 4.9, 10.3, 6.9, 8.3615, 4.6, 4.5, 
3.9, 3.7, 3.5, 3.4, 3.8, 3.1, 3.3, 3.5, 3.1, 3.7, 5.8, 6.9, 5.6, 
5.7, 5.3, 6.5, 7.9, 8.1, 3, 3.3, 3.7, 3.7, 3, 3.7, 5.1, 5.8, 
4.6, 3.2, 3.5, 2.9, 8.9, 2.7, 2.9, 2.8, 2.8, 2.9, 4, 3.8, 3.9, 
4.2, 4.3, 2.7, 10.2, 3.3, 2.8, 6.3, 3.4, 3.5, 4.2, 2.4, 6, 7.6, 
7.9, 10.2, 8.6, 6.1, 7.5, 6.9, 5.4, 6.4, 6.4, 7.1, 6.1, 5.3, 
4.3, 4.7, 3.9, 5.7), Log.10.Depth.M = c(0.86332, 0.61278, 0.50515, 
0.32222, 0.6721, 0.49136, 0.716, 0.61278, 0.87506, 0.44716, 0.53148, 
0.5563, 0.81291, 0.74819, 0.95809, 0.6141, 0.49136, 0.5563, 0.60206, 
0.64345, 0.53148, 0.5563, 0.47712, 0.62325, 0.54407, 0.51851, 
0.91593, 0.88024, 0.93952, 0.54407, 0.8651, 0.4908, 0.50515, 
0.90358, 0.8848, 0.94939, 0.57978, 0.95506, 0.6721, 0.72428, 
0.4624, 0.54407, 0.60206, 0.51851, 0.94448, 0.44716, 0.68124, 
0.65321, 0.38021, 0.68124, 0.63347, 0.60206, 0.70757, 0.51851, 
0.60206, 0.5563, 0.62325, 0.97093, 0.44716, 0.39794, 0.6902, 
1.01284, 0.84354, 0.92228, 0.66276, 0.65321, 0.59106, 0.5682, 
0.54407, 0.53148, 0.57978, 0.49136, 0.51851, 0.54407, 0.49136, 
0.5682, 0.76626, 0.83885, 0.74819, 0.75587, 0.72428, 0.81291, 
0.89763, 0.90849, 0.47712, 0.51851, 0.5682, 0.5682, 0.47712, 
0.5682, 0.70757, 0.76343, 0.66276, 0.50515, 0.54407, 0.4624, 
0.94939, 0.43136, 0.4624, 0.44716, 0.44716, 0.4624, 0.60206, 
0.57978, 0.59106, 0.62325, 0.63347, 0.43136, 1.0086, 0.51851, 
0.44716, 0.79934, 0.53148, 0.54407, 0.62325, 0.38021, 0.77815, 
0.88081, 0.89763, 1.0086, 0.9345, 0.78533, 0.87506, 0.83885, 
0.73239, 0.80618, 0.80618, 0.85126, 0.78533, 0.72428, 0.63347, 
0.6721, 0.59106, 0.75587), Profundidad.pico.H = c(7.2, 4.2, 3.1, 
2.2, 4.5, 3.5, 5, 4, 11.5, 2.8, 2.9, 3.7, 6.4, 5.4, 8.9, 5.2, 
3, 3.6, 3.8, 4, 4.1, 3.3, 3.1, 4.1, 3.6, 3.9, 6.4, 6.6, 11.3, 
3.3, 8.2, 3.2, 3, 7.5, 7.6, 8.4, 4, 8.8, 4.7, 5.7, 3.1, 2.9, 
3.6, 3.2, 7.7, 2.9, 5, 4.3, 2.4, 4.5, 3.8, 4, 5.1, 3.4, 3.7, 
4.1, 4.8, 10.7, 2.6, 2.3, 5.4, 10.4, 7.6, 8.8, 5, 4.7, 3.8, 3.7, 
3.9, 3.5, 3.6, 3.2, 3.1, 3.5, 3.1, 3.5, 5.9, 7.2, 5.3, 5.5, 5.2, 
6.5, 8.5, 8.4, 3.2, 3.1, 3.5, 3.5, 2.6, 3.6, 4.7, 5.7, 4.8, 2.6, 
3.3, 3.3, 9.3, 2.5, 2.9, 2.9, 2.8, 3.5, 4.1, 4.1, 4, 3.9, 4, 
2.8, 10.5, 3.2, 2.9, 6.5, 3.3, 3.5, 4.2, 2.2, 6.8, 6.5, 7.9, 
10.5, 9.1, 5.9, 7.4, 6.8, 5.2, 6.4, 6.5, 6.7, 5.8, 5.4, 4.4, 
4.5, 3.9, 5.3), Log.10.Depth.H = c(0.85733, 0.62325, 0.49136, 
0.34242, 0.65321, 0.54407, 0.69897, 0.60206, 1.0607, 0.44716, 
0.4624, 0.5682, 0.80889, 0.73239, 0.94743, 0.71181, 0.47712, 
0.5563, 0.57978, 0.60206, 0.61278, 0.51851, 0.49136, 0.61278, 
0.5563, 0.59106, 0.80277, 0.81757, 1.05154, 0.51851, 0.91593, 
0.49861, 0.47712, 0.87622, 0.88195, 0.92221, 0.60206, 0.94596, 
0.6721, 0.75587, 0.49136, 0.4624, 0.5563, 0.50515, 0.88649, 0.4624, 
0.69897, 0.63347, 0.38021, 0.65321, 0.57978, 0.60206, 0.70757, 
0.53148, 0.5682, 0.61278, 0.68124, 1.03072, 0.41497, 0.36173, 
0.73239, 1.01703, 0.88309, 0.94313, 0.69897, 0.6721, 0.57978, 
0.5682, 0.59106, 0.54407, 0.5563, 0.50515, 0.49136, 0.54407, 
0.49136, 0.54407, 0.77159, 0.85733, 0.72428, 0.74036, 0.716, 
0.81291, 0.92942, 0.92428, 0.50515, 0.49136, 0.54407, 0.54407, 
0.41497, 0.5563, 0.6721, 0.75587, 0.68124, 0.41497, 0.51851, 
0.51851, 0.96848, 0.39794, 0.4624, 0.4624, 0.44716, 0.54407, 
0.61278, 0.61278, 0.60206, 0.59106, 0.60206, 0.44716, 1.02119, 
0.50515, 0.4624, 0.81291, 0.51851, 0.54407, 0.62325, 0.34242, 
0.83251, 0.81291, 0.89763, 1.02119, 0.95904, 0.77085, 0.86923, 
0.83251, 0.716, 0.80618, 0.81291, 0.82607, 0.76343, 0.73239, 
0.64345, 0.65321, 0.59106, 0.72428)), class = "data.frame", row.names = c(NA, 
-134L))
0

There are 0 best solutions below