Seite 1 von 1

logarithmische Achse in plotly

Verfasst: So Sep 08, 2019 9:52 pm
von retep
Hallo,

ich wollte die Community um folgendes Problem bitten: Im Anhang ist eine Textdatei. Mit Hilfe dieser Daten wollte ich gerne einen xy-Plot mit logarithmischer Achse in plotly erstellen. Mit ggplot ist das kein Problem. Wenn ich denselben Plot mit plotly erstellen möchte, komme ich ins Schleudern. Normalerweise ist es mit ggplotly ohne weiters möglich jeden Plot in Plotly zu transferieren. Soweit ich weiß
hat Plotly Schwierigkeiten mit der Übernahme der Daten wenn es um logarithmische Achsendarstellung geht.

Leider komme ich mit Plotly nicht klar. Jeder Versuch dieselbe Darstellung zu plotten misslingt. Aus diesem Grund wollte ich anfragen ob jemand weiter weiß wie ich eine ähnliche Darstellung wie in den angezeigten Plots bekommen kann.

Hier sind die Befehle für ggplot:

Code: Alles auswählen


p <- ggplot(M_Klasse, aes(Ge, Ga, fill = Class, na.rm =TRUE))+
  geom_point(aes(colour = Class), alpha = 0.9, size=3.5 ,na.rm = TRUE)+
  #stat_smooth(method="lm")+
  scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x),
                labels = trans_format("log10", math_format(10^.x))) +
  #scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
              #labels = trans_format("log10", math_format(10^.x))) +
  scale_fill_brewer(palette="Paired")+
  labs(title = "Geochemie Meteorite",
       subtitle = "Crossplot",
       caption = "Data Source:",
       x = " Ge [ppm]", y = " Ga [ppm]",
       tag = "C")+
    theme_minimal(base_size = 15)
 ggplotly(p)
 
Und hier der Befehl von ggplot für plotly:

Code: Alles auswählen

p <- ggplot(M_Klasse, aes(Ge, Ga, fill = Class, na.rm =TRUE))+
  geom_point(aes(colour = Class), alpha = 0.9, size=3.5 ,na.rm = TRUE)+
  #stat_smooth(method="lm")+
  scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x),
                labels = trans_format("log10", math_format(10^.x))) +
  #scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
              #labels = trans_format("log10", math_format(10^.x))) +
  scale_fill_brewer(palette="Paired")+
  labs(title = "Geochemie Meteorite",
       subtitle = "Crossplot",
       caption = "Data Source:",
        x = " Ge [ppm]", y = " Ga [ppm]",
       tag = "C")+
    theme_minimal(base_size = 15)
ggplotly(p)
Hier der Versuch in plotly direkt:

Code: Alles auswählen

p <- plot_ly (type="scatter",
     M_Klasse, x = ~Ge, y= ~ Ga)
p <- layout(p, xaxis = list(type = "log"))
plot_ly(p)
Wenn ich diesen Befehl ausführen lasse bekomme ich folgende Fehlermeldung:

Error: First argument, `data`, must be a data frame or shared data.

Spätestens hier weiß ich nicht mehr weiter und die Webrecherche bringt auch nichts richtiges.
Zum besseren Verständnis und Nachvollziehbarkeit habe ich einen Ausriss aus dem Datensatz angehängt.

Vielen Dank für Eure Mühe und Unterstützung!

retep

Re: logarithmische Achse in plotly

Verfasst: Mo Sep 09, 2019 7:49 am
von bigben
Hi!

Ch kenne mich mit plotly nicht aus, aber generell kann man Argumente für Funktionen entweder durch ihre Reihenfolge oder durch ihren Namen zuordnen. Wenn man mischt, sollten in allen mir bekannten Sprachen die Argumente mit Namen nach denen ohne kommen. So lese ich auch die Fehlermeldung. Stell M_Klasse mal vor Type.

LG,
Bernhard

Re: logarithmische Achse in plotly

Verfasst: Mo Sep 09, 2019 3:09 pm
von ruedi_br
so isses - oder anders ausgedrückt RTFM, dort steht:
Usage
plot_ly(data = data.frame(), ..., type = NULL, name, color,
colors = NULL, alpha = NULL, stroke, strokes = NULL,
alpha_stroke = 1, size, sizes = c(10, 100), span, spans = c(1, 20),
symbol, symbols = NULL, linetype, linetypes = NULL, split, frame,
width = NULL, height = NULL, source = "A")
Grüße
Ruedi

Re: logarithmische Achse in plotly

Verfasst: Mo Sep 09, 2019 8:23 pm
von retep
Hallo Bernhard, hallo Rudi,

habt vielen Dank für Eure Tipps, langsam taste ich mich ran! Obwohl mir es ggplot leichter fällt zu verstehen mit diesen Befehl funktionieren zumindest die Basics:

Code: Alles auswählen

M_Klasse %>%
  group_by(Class) %>%
  plot_ly(x = ~Ge, y = ~Ga, color=~ Class) %>%
  add_markers(hoverinfo="yes")
 
Jetzt fehlt noch die logarithmische Achse und mit den subplot2 (facets in ggplot) habe ich noch Schwierigkeiten.

Ich melde mich wenn ich total daneben liege. Oder ich habe die Plots so wie ich es haben will.

LG retep