Der Schlüssel hier ist, einen Weg zu finden Ihren Faktor Variable Quarter
, neu zu ordnen, bevor Sie die Datenpunkte zeichnen. Dies sollte helfen:
library(ggplot2)
# example data
df = structure(list(Fund = structure(c(2L, 1L), .Label = c(" Fund XI-A, L.P.", "Opportunity Fund, LP"), class = "factor"),
Date = structure(1:2, .Label = c("2013-Q3", "2017-Q1"), class = "factor"),
Quarter = structure(1:2, .Label = c("Q1", "Q12"), class = "factor"),
Commitment = structure(1:2, .Label = c("$20,000,000", "$35,000,000"), class = "factor"),
NAV = structure(1:2, .Label = c("$247,764", "$40,888,084"), class = "factor"),
Ratio = c(0.01, 1.17)), .Names = c("Fund", "Date", "Quarter", "Commitment", "NAV", "Ratio"), class = "data.frame", row.names = c(NA, -2L))
# keep the order of your factor variable as it is
ggplot(data=df,aes(Quarter))+
geom_point(aes(x = Quarter, y = Ratio, color = Fund))+
theme(axis.text.x = element_text(angle = 65, hjust = 1))
# change the order and plot again
df$Quarter <- reorder(df$Quarter, 2:1)
ggplot(data=df,aes(Quarter))+
geom_point(aes(x = Quarter, y = Ratio, color = Fund))+
theme(axis.text.x = element_text(angle = 65, hjust = 1))
Als allgemeine Lösung (das heißt, wenn Sie nicht nur 2 Faktorstufen haben) Sie df$Quarter <- reorder(df$Quarter, length(df$Quarter):1)
neu anordnen können.
können Sie Ihre Daten 'mydata' eingeben, indem Sie' dput (mydata) 'in die Konsole eingeben und die Ausgabe zu Ihrer Frage hinzufügen? – brettljausn
> dput (mydata) Struktur (Liste (Fonds = Struktur (c (2L, 1L), .Label = c ("Fonds XI-A, LP", "Opportunity Fonds, LP"), class = "Faktor"), Datum = Struktur (1: 2, .Label = c ("2013-Q3", "2017-Q1"), class = "Faktor"), Quarter = Struktur (1: 2, .Label = c (" Q1 ", " Q12 "), Klasse =" Faktor "), Commitment = Struktur (1: 2, .Label = c (" $ 20,000,000 ", " $ 35,000,000 "), Klasse =" Faktor "), NAV = Struktur (1: 2, .Label = c ("$ 247,764", "$ 40,888,084"), Klasse = "Faktor"), Verhältnis = c (0,01, 1,17)), .Names = c ("Fund", "Datum", "Quartal", "Commitment", "NAV", "Ratio"), class = "data.frame", row.names = c (NA, -2L)) – gurtej
was @brettljausn bedeutet, ist eine kleine Stichprobe Ihrer Daten 'Mydata'. So können wir Ihren Code ausführen .. – Dan