stat_smooth : could not find function "ns"

758 views
Skip to first unread message

Manuel Spínola

unread,
May 16, 2011, 11:30:24 AM5/16/11
to ggp...@googlegroups.com
Dear list members,

I am making a plot with ggplot2 using stat_smooth as I did it before but now is telling me that it did not find the function ns. I did it before and everything was fine.

> dput(juntaranf)
structure(list(ident = c(1L, 6L, 8L, 13L, 14L, 15L, 17L, 19L, 
20L, 23L, 24L, 25L, 26L, 27L, 30L, 31L, 33L, 34L, 36L, 38L, 42L, 
43L, 44L, 45L, 48L, 49L, 51L, 52L, 53L, 54L, 55L, 57L, 59L, 60L, 
62L, 63L, 65L, 68L, 69L, 70L, 71L, 72L), Nombre = structure(c(41L, 
19L, 30L, 58L, 18L, 29L, 42L, 21L, 9L, 52L, 15L, 50L, 5L, 6L, 
57L, 69L, 11L, 1L, 16L, 64L, 55L, 25L, 26L, 56L, 14L, 28L, 71L, 
70L, 39L, 4L, 27L, 24L, 23L, 7L, 13L, 38L, 37L, 44L, 36L, 2L, 
43L, 10L), .Label = c("Afluente Peje", "Ajuntaderas", "Alemania", 
"Balsar ", "Bijagual 1", "Bijagual 2", "Boca Brava", "Boca Chica", 
"Boca Toma", "Brusmalis", "Cabagra", "Cajon", "Camaronera", "Caña Blancal", 
"Caracol", "Cataratas 1", "Cataratas 2", "Ceibo", "Chi0 Kicha", 
"Coli0s 1", "Coli0s 2", "Concepcion", "Coronado", "Cuatro Bocas ", 
"Curre 2", "Curre1", "Delicias", "Desfogue", "Dibujada", "El Tigre", 
"El Valle", "Estero Bocon", "Estero Caite", "Estero Guarumal", 
"Estero Muerto ", "Estero Seco", "Estero Zacate", "Estirahuevos", 
"Filadelfia", "Fortu0", "General Viejo", "Guagaral", "Hacienda", 
"Isla Violines", "Isla Viuda", "La Tinta", "Lagu0 La Danta", 
"Lagu0 Silencio", "Las Brisas", "Ocochovi", "Paraiso", "Paso La Tinta", 
"Paso Real 1", "Paso Real 2", "Paso Real 3", "Progreso", "Quebrada Veraguas", 
"Remolinos", "Rio Cañas", "Rio Convento", "Rio Mosca", "Rio Pacuar", 
"Salitre", "San Andres", "San Cristobal 1", "San Cristobal 2", 
"San Pedro", "So0dor", "SPMI", "Tanque de Oscilacion", "Tuberia de Presion", 
"Ujarras", "Vergel"), class = "factor"), PSA = c(0, 56.481, 0, 
48.974, 6.605, 49.639, 13.503, 99.751, 74.472, 32.244, 22.507, 
1.025, 23.897, 58.677, 120.372, 100.945, 0, 115.177, 0, 0, 0, 
0, 0, 154.938, 103.514, 95.397, 4.87, 0.472, 3.471, 3.091, 19.329, 
50.684, 7.553, 0, 0, 0, 0, 34.827, 6.946, 34.327, 142.046, 0), 
    PCA = c(65.301, 106.574, 0, 96.604, 80.966, 82.166, 40.394, 
    72.908, 85.789, 94.801, 66.6, 44.699, 121.898, 87.362, 28.129, 
    29.879, 147.827, 0, 19.51, 118.771, 30.088, 86.195, 31.557, 
    47.779, 0.351, 52.979, 57.578, 13.537, 19.313, 64.723, 1.959, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 41.928, 191.937), BPI = c(64.458, 
    0, 91.459, 0, 18.474, 0, 70.239, 32.092, 40.875, 11.69, 0, 
    0, 45.39, 71.457, 4.247, 3.473, 134.543, 177.2, 71.012, 15.207, 
    99.497, 55.64, 69.865, 27.374, 126.63, 27.689, 127.379, 190.875, 
    276.626, 160.28, 0, 0, 0, 0, 54.498, 4.198, 0, 71.446, 125.447, 
    7.196, 0, 39.739), BS = c(0, 97.223, 91.774, 100.817, 98.359, 
    71.433, 40.736, 60.384, 38.429, 94.329, 124.231, 115.426, 
    51.368, 52.072, 136.465, 137.984, 0, 0, 0, 0, 0, 54.229, 
    0, 0, 1.802, 0.587, 33.419, 10.158, 0.347, 0, 0, 0, 0, 0, 
    2.489, 0, 0, 0, 0, 0, 0, 0), AQ = c(0, 0, 0, 0, NA, NA, 21.855, 
    0.575, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0), total = c(129.759, 
    260.278, 183.233, 246.395, 204.404, 203.238, 186.727, 265.71, 
    239.565, 233.064, 213.338, 161.15, 242.553, 269.568, 289.213, 
    272.281, 282.37, 292.377, 90.522, 133.978, 129.585, 196.064, 
    101.422, 230.091, 232.297, 176.652, 223.246, 215.042, 299.757, 
    228.094, 21.288, 50.684, 7.553, 0, 56.987, 4.198, 0, 106.273, 
    132.393, 41.523, 183.974, 231.676), I_Shannon = c(0.6918, 
    10.621, 0.6931, 10.337, 11.291, 10.677, 14.584, 13.072, 13.533, 
    11.807, 0.9874, 0.7752, 12.337, 13.453, 10.829, 1.06, 0.6865, 
    0.6916, 0.6119, 0.6119, 0.6589, 1.062, 0.675, 0.9886, 0.8235, 
    11.304, 11.405, 0.8444, 0.8114, 0.8479, 0.3972, 0, 0, 0, 
    0.3133, 0, 0, 0.6929, 0.4518, 0.5339, 0.5822, 0.648), sitio = structure(c(29L, 
    15L, 24L, 38L, 14L, 23L, 30L, 16L, 7L, 34L, 12L, 33L, 4L, 
    5L, 37L, 40L, 9L, 1L, 13L, 39L, 35L, 20L, 19L, 36L, 11L, 
    22L, 42L, 41L, 28L, 3L, 21L, 18L, 17L, 6L, 10L, 27L, 26L, 
    32L, 25L, 2L, 31L, 8L), .Label = c("Afluente Peje", "Ajuntaderas", 
    "Balsar", "Bijagual 1", "Bijagual 2", "Boca Brava", "Boca Toma", 
    "Brusmalis", "Cabagra", "Camaronera", "Caña Blancal", "Caracol", 
    "Cataratas 1", "Ceibo", "China Kichá", "Colinas 2", "Coronado", 
    "Cuatro Bocas", "Curre 1", "Curre 2", "Delicias", "Desfogue", 
    "Dibujada", "El Tigre", "Estero Seco", "Estero Zacate", "Estirahuevos", 
    "Filadelfia", "General Viejo", "Guagaral", "Hacienda", "Isla Violines", 
    "Ocochovi", "Paso La Tinta", "Paso Real 3", "Progreso", "Quebrada Veraguas", 
    "Remolinos", "San Andrés", "SPMI", "Tanque Oscilacion", "Tuberia Presion"
    ), class = "factor"), long = c(537320L, 556076L, 563554L, 
    569284L, 568502L, 565192L, 554885L, 562940L, 563467L, 568097L, 
    568858L, 571764L, 571571L, 572464L, 576561L, 576693L, 589826L, 
    593298L, 580207L, 583360L, 584373L, 582406L, 580621L, 573735L, 
    564151L, 556782L, 557865L, 558111L, 555446L, 552583L, 545940L, 
    543505L, 537610L, 541466L, 545819L, 545581L, 544906L, 540958L, 
    543375L, 555698L, 561382L, 606935L), lat = c(1046408L, 1017177L, 
    1013034L, 1012186L, 1010160L, 1007679L, 1003251L, 1000951L, 
    1002905L, 1005564L, 1006267L, 1005498L, 1003877L, 1003708L, 
    1003511L, 1004387L, 1014954L, 1010094L, 1003289L, 999276L, 
    993974L, 992877L, 992005L, 988424L, 991989L, 990632L, 992831L, 
    993733L, 997533L, 999404L, 992481L, 992196L, 1002104L, 990078L, 
    988568L, 987348L, 984209L, 971783L, 969577L, 979823L, 977861L, 
    976129L), Observada = c(0L, 11L, 15L, 9L, 12L, 11L, 4L, 14L, 
    13L, 12L, 17L, 14L, 17L, 9L, 0L, 10L, 0L, 7L, 9L, 6L, 0L, 
    2L, 1L, 7L, 0L, 12L, 12L, 8L, 7L, 0L, 9L, 0L, 6L, 0L, 5L, 
    0L, 0L, 7L, 11L, 3L, 5L, 3L), Chao = c(0, 12, 16.5, 9, 15, 
    11, 4, 15, 19, 12, 18, 20, 17.2, 9.75, 0, 10.5, 0, 7, 9.25, 
    9, 0, 3, 1, 10, 0, 12, 22, 9, 8.5, 0, 10, 0, 11, 0, 5, 0, 
    0, 7, 21, 3, 5, 3), Chao_SE = c(0, 0, 3.49, 0.73, 11.66, 
    0.54, 1.32, 3.4, 0, 0.54, 3.4, 0, 1.03, 2.29, 0, 3.74, 0, 
    0, 1.31, 0, 0, 0, 0, 0, 0, 0.73, 0, 0, 7.19, 0, 0, 0, 17.14, 
    0, 0, 0, 0, 0, 0, 0, 0, 1.32), ACE = c(0L, 12L, 18L, 9L, 
    17L, 11L, 5L, 16L, 17L, 12L, 18L, 17L, 18L, 11L, 0L, 12L, 
    0L, 7L, 10L, 14L, 0L, 0L, 0L, 9L, 0L, 12L, 19L, 9L, 11L, 
    0L, 11L, 0L, 21L, 0L, 5L, 0L, 0L, 7L, 18L, 3L, 5L, 4L), ACE_SE = c(0, 
    1.57, 1.92, 1.11, 2.18, 1.13, 1.03, 1.82, 1.79, 0.69, 1.97, 
    2.01, 2.11, 1.58, 0, 1.87, 0, 0, 1.53, 1.27, 0, 0, 0, 1.2, 
    0, 1.7, 2.31, 1.32, 1.67, 0, 1.62, 0, 0.97, 0, 1.1, 0, 0, 
    1.03, 2.26, 0.82, 1.1, 0.92), newvar = c(64.458, 97.223, 
    183.233, 100.817, 116.833, 71.433, 110.975, 92.476, 79.304, 
    106.019, 124.231, 115.426, 96.758, 123.529, 140.712, 141.457, 
    134.543, 177.2, 71.012, 15.207, 99.497, 109.869, 69.865, 
    27.374, 128.432, 28.276, 160.798, 201.033, 276.973, 160.28, 
    0, 0, 0, 0, 56.987, 4.198, 0, 71.446, 125.447, 7.196, 0, 
    39.739), propbosque = c(0.20528025477707, 0.309627388535032, 
    0.583544585987261, 0.321073248407643, 0.372079617834395, 
    0.227493630573248, 0.353423566878981, 0.294509554140127, 
    0.25256050955414, 0.337640127388535, 0.395640127388535, 0.36759872611465, 
    0.308146496815287, 0.393404458598726, 0.448127388535032, 
    0.4505, 0.428480891719745, 0.564331210191083, 0.226152866242038, 
    0.0484299363057325, 0.316869426751592, 0.34990127388535, 
    0.2225, 0.0871783439490446, 0.409019108280255, 0.0900509554140127, 
    0.512095541401274, 0.640232484076433, 0.882079617834395, 
    0.510445859872611, 0, 0, 0, 0, 0.181487261146497, 0.0133694267515924, 
    0, 0.227535031847134, 0.399512738853503, 0.0229171974522293, 
    0, 0.126557324840764)), .Names = c("ident", "Nombre", "PSA", 
"PCA", "BPI", "BS", "AQ", "total", "I_Shannon", "sitio", "long", 
"lat", "Observada", "Chao", "Chao_SE", "ACE", "ACE_SE", "newvar", 
"propbosque"), row.names = c(NA, -42L), class = "data.frame")


> p1 = ggplot(juntaranf, aes(propbosque, ACE)) + stat_smooth(method= MASS::glm.nb, formula = y ~ ns(x,3)) + geom_point() +
+ xlab("Proporción de área de bosque") + ylab("Número de especies") + theme_bw() + opts(axis.title.x = theme_text(size = 12, vjust = -0.5)) + annotate("text",x=0.1,y=28,label="Anfibios") 
> p1
Error in eval(expr, envir, enclos) : could not find function "ns"


Best,

Manuel


--
Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspi...@una.ac.cr
mspin...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río
Institutional website: ICOMVIS

Ben Bolker

unread,
May 14, 2011, 5:16:36 AM5/14/11
to ggp...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11-05-16 11:30 AM, Manuel Sp�nola wrote:
> Dear list members,
>
> I am making a plot with ggplot2 using stat_smooth as I did it before but
> now is telling me that it did not find the function ns. I did it before
> and everything was fine.

You probably forgot

library(splines)

?

>
>> dput(juntaranf)
> structure(list(ident = c(1L, 6L, 8L, 13L, 14L, 15L, 17L, 19L,
> 20L, 23L, 24L, 25L, 26L, 27L, 30L, 31L, 33L, 34L, 36L, 38L, 42L,
> 43L, 44L, 45L, 48L, 49L, 51L, 52L, 53L, 54L, 55L, 57L, 59L, 60L,
> 62L, 63L, 65L, 68L, 69L, 70L, 71L, 72L), Nombre = structure(c(41L,
> 19L, 30L, 58L, 18L, 29L, 42L, 21L, 9L, 52L, 15L, 50L, 5L, 6L,
> 57L, 69L, 11L, 1L, 16L, 64L, 55L, 25L, 26L, 56L, 14L, 28L, 71L,
> 70L, 39L, 4L, 27L, 24L, 23L, 7L, 13L, 38L, 37L, 44L, 36L, 2L,
> 43L, 10L), .Label = c("Afluente Peje", "Ajuntaderas", "Alemania",
> "Balsar ", "Bijagual 1", "Bijagual 2", "Boca Brava", "Boca Chica",

> "Boca Toma", "Brusmalis", "Cabagra", "Cajon", "Camaronera", "Ca�a Blancal",

> "Caracol", "Cataratas 1", "Cataratas 2", "Ceibo", "Chi0 Kicha",
> "Coli0s 1", "Coli0s 2", "Concepcion", "Coronado", "Cuatro Bocas ",
> "Curre 2", "Curre1", "Delicias", "Desfogue", "Dibujada", "El Tigre",
> "El Valle", "Estero Bocon", "Estero Caite", "Estero Guarumal",
> "Estero Muerto ", "Estero Seco", "Estero Zacate", "Estirahuevos",
> "Filadelfia", "Fortu0", "General Viejo", "Guagaral", "Hacienda",
> "Isla Violines", "Isla Viuda", "La Tinta", "Lagu0 La Danta",
> "Lagu0 Silencio", "Las Brisas", "Ocochovi", "Paraiso", "Paso La Tinta",
> "Paso Real 1", "Paso Real 2", "Paso Real 3", "Progreso", "Quebrada
> Veraguas",

> "Remolinos", "Rio Ca�as", "Rio Convento", "Rio Mosca", "Rio Pacuar",

> "Brusmalis", "Cabagra", "Camaronera", "Ca�a Blancal", "Caracol",
> "Cataratas 1", "Ceibo", "China Kich�", "Colinas 2", "Coronado",

> "Cuatro Bocas", "Curre 1", "Curre 2", "Delicias", "Desfogue",
> "Dibujada", "El Tigre", "Estero Seco", "Estero Zacate", "Estirahuevos",
> "Filadelfia", "General Viejo", "Guagaral", "Hacienda", "Isla Violines",
> "Ocochovi", "Paso La Tinta", "Paso Real 3", "Progreso", "Quebrada
> Veraguas",

> "Remolinos", "San Andr�s", "SPMI", "Tanque Oscilacion", "Tuberia

> + xlab("Proporci�n de �rea de bosque") + ylab("N�mero de especies") +


> theme_bw() + opts(axis.title.x = theme_text(size = 12, vjust = -0.5)) +
> annotate("text",x=0.1,y=28,label="Anfibios")
>> p1
> Error in eval(expr, envir, enclos) : could not find function "ns"
>
>
> Best,
>
> Manuel
>
>
> --

> *Manuel Sp�nola, Ph.D.*
> Instituto Internacional en Conservaci�n y Manejo de Vida Silvestre


> Universidad Nacional
> Apartado 1350-3000
> Heredia
> COSTA RICA

> mspi...@una.ac.cr <mailto:mspi...@una.ac.cr>
> mspin...@gmail.com <mailto:mspin...@gmail.com>
> Tel�fono: (506) 2277-3598
> Fax: (506) 2237-7036
> Personal website: Lobito de r�o
> <https://sites.google.com/site/lobitoderio/>
> Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>
>
> --
> You received this message because you are subscribed to the ggplot2
> mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3OSHQACgkQc5UpGjwzenPZVACfVuHL+xTeAvQyiy5kpuDtu2it
sXkAoJF6kSYVuJn6bTVVY1Kn7MED4eCr
=2/El
-----END PGP SIGNATURE-----

Manuel Spínola

unread,
May 16, 2011, 12:18:06 PM5/16/11
to Ben Bolker, ggp...@googlegroups.com
Thank you very much Ben.

That was the case.
I guess I did have it before when I downloaded other packages.

Best,

Manuel

El 14 de mayo de 2011 03:16, Ben Bolker <bbo...@gmail.com> escribió:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11-05-16 11:30 AM, Manuel Spínola wrote:
> Dear list members,
>
> I am making a plot with ggplot2 using stat_smooth as I did it before but
> now is telling me that it did not find the function ns. I did it before
> and everything was fine.

 You probably forgot

library(splines)

?

>
>> dput(juntaranf)
> structure(list(ident = c(1L, 6L, 8L, 13L, 14L, 15L, 17L, 19L,
> 20L, 23L, 24L, 25L, 26L, 27L, 30L, 31L, 33L, 34L, 36L, 38L, 42L,
> 43L, 44L, 45L, 48L, 49L, 51L, 52L, 53L, 54L, 55L, 57L, 59L, 60L,
> 62L, 63L, 65L, 68L, 69L, 70L, 71L, 72L), Nombre = structure(c(41L,
> 19L, 30L, 58L, 18L, 29L, 42L, 21L, 9L, 52L, 15L, 50L, 5L, 6L,
> 57L, 69L, 11L, 1L, 16L, 64L, 55L, 25L, 26L, 56L, 14L, 28L, 71L,
> 70L, 39L, 4L, 27L, 24L, 23L, 7L, 13L, 38L, 37L, 44L, 36L, 2L,
> 43L, 10L), .Label = c("Afluente Peje", "Ajuntaderas", "Alemania",
> "Balsar ", "Bijagual 1", "Bijagual 2", "Boca Brava", "Boca Chica",
> "Boca Toma", "Brusmalis", "Cabagra", "Cajon", "Camaronera", "Caña Blancal",

> "Caracol", "Cataratas 1", "Cataratas 2", "Ceibo", "Chi0 Kicha",
> "Coli0s 1", "Coli0s 2", "Concepcion", "Coronado", "Cuatro Bocas ",
> "Curre 2", "Curre1", "Delicias", "Desfogue", "Dibujada", "El Tigre",
> "El Valle", "Estero Bocon", "Estero Caite", "Estero Guarumal",
> "Estero Muerto ", "Estero Seco", "Estero Zacate", "Estirahuevos",
> "Filadelfia", "Fortu0", "General Viejo", "Guagaral", "Hacienda",
> "Isla Violines", "Isla Viuda", "La Tinta", "Lagu0 La Danta",
> "Lagu0 Silencio", "Las Brisas", "Ocochovi", "Paraiso", "Paso La Tinta",
> "Paso Real 1", "Paso Real 2", "Paso Real 3", "Progreso", "Quebrada
> Veraguas",
> "Remolinos", "Rio Cañas", "Rio Convento", "Rio Mosca", "Rio Pacuar",
>     "Brusmalis", "Cabagra", "Camaronera", "Caña Blancal", "Caracol",
>     "Cataratas 1", "Ceibo", "China Kichá", "Colinas 2", "Coronado",

>     "Cuatro Bocas", "Curre 1", "Curre 2", "Delicias", "Desfogue",
>     "Dibujada", "El Tigre", "Estero Seco", "Estero Zacate", "Estirahuevos",
>     "Filadelfia", "General Viejo", "Guagaral", "Hacienda", "Isla Violines",
>     "Ocochovi", "Paso La Tinta", "Paso Real 3", "Progreso", "Quebrada
> Veraguas",
>     "Remolinos", "San Andrés", "SPMI", "Tanque Oscilacion", "Tuberia
> + xlab("Proporción de área de bosque") + ylab("Número de especies") +

> theme_bw() + opts(axis.title.x = theme_text(size = 12, vjust = -0.5)) +
> annotate("text",x=0.1,y=28,label="Anfibios")
>> p1
> Error in eval(expr, envir, enclos) : could not find function "ns"
>
>
> Best,
>
> Manuel
>
>
> --
> *Manuel Spínola, Ph.D.*
> Instituto Internacional en Conservación y Manejo de Vida Silvestre

> Universidad Nacional
> Apartado 1350-3000
> Heredia
> COSTA RICA
> Teléfono: (506) 2277-3598
> Fax: (506) 2237-7036
> Personal website: Lobito de río
> <https://sites.google.com/site/lobitoderio/>
> Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>
>
> --
> You received this message because you are subscribed to the ggplot2
> mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3OSHQACgkQc5UpGjwzenPZVACfVuHL+xTeAvQyiy5kpuDtu2it
sXkAoJF6kSYVuJn6bTVVY1Kn7MED4eCr
=2/El
-----END PGP SIGNATURE-----

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2



--
Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspi...@una.ac.cr
mspin...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río
Institutional website: ICOMVIS

陈凯

unread,
May 31, 2014, 9:18:59 AM5/31/14
to ggp...@googlegroups.com
Thanks very much! I have solved this problem according to your suggestion, it helps! 

在 2011年5月14日星期六UTC+8下午5时16分36秒,Ben Bolker写道:
Reply all
Reply to author
Forward
0 new messages