nicholasehamilton / ggtern

Extension to ggplot2 for plotting ternary diagrams
www.ggtern.com
55 stars 14 forks source link

Conflict with ggplot #21

Open gilleschapron opened 9 years ago

gilleschapron commented 9 years ago

Hi Nicolas,

In fact, this is not an issue of your package, but perhaps, you could give me some advice.

I have create a function that use your package in my one 'private' package. My package intensively use ggplot2 in many function, so I use

@import ggplot2

to globaly import it.

I first do the same thing with ggtern :

@import ggtern

with consequence that my function that create the ternary plot work perfectly. But other function that use only ggplot2 consequently do not anymore... I have some

object of type 'closure' is not subsettable

error that I have not if I do not build my function using ggtern in my package.

So, a thing that could I suppose solve the problem is to stop using @import ggtern in my function and to call all the specific ggtern function with "ggtern::".

I have tried to to do so in the following code (sorry its not reproductible, but I can give you my all code if necessary):

  plot.demol <- ggplot() + ggtern::coord_tern() +
    ggtern::geom_segment(data = lim.demolon,
                 ggtern::aes(x = y, y = x, z = z,
                     xend = yend, yend = xend, zend = zend),
                 size = 0.5) +
    geom_text(data = type.sol, ggtern::aes(x = L, y = T, z = R, label = txt),
              size = 2.5, lineheight = 0.75) +
    geom_point(data = granu,
               mapping = ggtern::aes(y = T, x = L, z = R, shape = sect),
               colour = formcoul, fill = formcoul, size = 2) +
    ggtern::scale_T_continuous(name = expression("Argile (< "*2*" µm)")) +
    ggtern::scale_L_continuous(name = expression("Limon ("*2*" à "*20*" µm)")) +
    ggtern::scale_R_continuous(name = expression("Sable (> "*20*" µm)")) +
    ggtern::theme_showarrows() +
    ggtern::theme_arrowlong() +
    ggtern::theme_hidetitles() +
    ggtitle(element_blank()) +
    ggtern::theme(axis.tern.title = element_text(size = 8, face = "bold"),
          axis.tern.text = element_text(size = 7),
          legend.title = element_blank(),
          legend.text = element_text(size = 6),
          legend.background = element_blank(),
          legend.key = element_blank(),
          legend.direction = "horizontal",
          legend.position = c(0.5, 1),
          legend.justification = c(0.5, 0.35),
          plot.margin= ggtern::unit(c(0.05, 0, 0, 0), "null")) +
    scale_shape_manual(values = sect_concerne[[3]],
                       breaks = sect_concerne[[1]])

Infortunately I have the error that come I think from ggplot2 that do not interpret a function:

Error in UseMethod("scale_clone") : no applicable method for 'scale_clone' applied to an object of class "c('tern_T', 'continuous_ternary', 'scale')"

Could you have any idea to help me about it ? My apologies if I'm not in the best place to ask my question...

Regards, Gilles

gilleschapron commented 9 years ago

Redondant with issue #19, so you can close it.

nicholasehamilton commented 9 years ago

Thanks for reminding me, I will attend to your issue. Cheers.

Nicholas Hamilton School of Materials Science and Engineering

University of New South Wales (Australia)

www.ggtern.comhttp://www.ggtern.com

On 26 May 2015, at 8:47 pm, Gilles Chapron notifications@github.com<mailto:notifications@github.com> wrote:

Hi Nicolas,

In fact, this is not an issue of your package, but perhaps, you could give me some advice.

I have create a function that use your package in my one 'private' package. My package intensively use ggplot2 in many function, so I use

@importhttps://github.com/import ggplot2 to globaly import it.

I first do the same thing with ggtern :

@importhttps://github.com/import ggtern

with consequence that my function that create the ternary plot work perfectly. But other function that use only ggplot2 consequently do not anymore... I have some

object of type 'closure' is not subsettable

error that I have not if I do not build my function using ggtern in my package.

So, a thing that could I suppose solve the problem is to stop using @importhttps://github.com/import ggtern in my function and to call all the specific ggtern function with "ggtern::".

I have tried to to do so in the following code (sorry its not reproductible, but I can give you my all code if necessary):

plot.demol <- ggplot() + ggtern::coord_tern() + ggtern::geom_segment(data = lim.demolon, ggtern::aes(x = y, y = x, z = z, xend = yend, yend = xend, zend = zend), size = 0.5) + geom_text(data = type.sol, ggtern::aes(x = L, y = T, z = R, label = txt), size = 2.5, lineheight = 0.75) + geom_point(data = granu, mapping = ggtern::aes(y = T, x = L, z = R, shape = sect), colour = formcoul, fill = formcoul, size = 2) + ggtern::scale_T_continuous(name = expression("Argile (< "2" µm)")) + ggtern::scale_L_continuous(name = expression("Limon ("2" à "20" µm)")) + ggtern::scale_R_continuous(name = expression("Sable (> "20" µm)")) + ggtern::theme_showarrows() + ggtern::theme_arrowlong() + ggtern::theme_hidetitles() + ggtitle(element_blank()) + ggtern::theme(axis.tern.title = element_text(size = 8, face = "bold"), axis.tern.text = element_text(size = 7), legend.title = element_blank(), legend.text = element_text(size = 6), legend.background = element_blank(), legend.key = element_blank(), legend.direction = "horizontal", legend.position = c(0.5, 1), legend.justification = c(0.5, 0.35), plot.margin= ggtern::unit(c(0.05, 0, 0, 0), "null")) + scale_shape_manual(values = sect_concerne[[3]], breaks = sect_concerne[[1]])

Infortunately I have the error that come I think from ggplot2 that do not interpret a function:

Error in UseMethod("scale_clone") : no applicable method for 'scale_clone' applied to an object of class "c('tern_T', 'continuous_ternary', 'scale')"

Could you have any idea to help me about it ? My apologies if I'm not in the best place to ask my question...

Regards, Gilles

— Reply to this email directly or view it on GitHubhttps://github.com/nicholasehamilton/ggtern/issues/21.