2017-07-20 3 views
0

Ich versuche, minimale und maximale Temperaturen zu plotten, und mit einem normalen Punkt-Plot (mit pch = 16) sieht es normal aus, aber wenn ich den Plot-Typ zu Zeile ändern (mit type = "l"), fügt es eine Linie hinzu das scheint die ersten und letzten Werte zu verbinden.Geraden wird zum Liniendiagramm hinzugefügt?

Gibt es eine Möglichkeit, die gerade Linie loszuwerden, die den ersten und letzten Wert verbindet? & Warum passiert das?

Hier ist die Datenstruktur:

> y 
Source: local data frame [365 x 6] 
Groups: Month [12] 

    Month Day Tmp_min MonthDay_min Tmp_max 
    <fctr> <chr> <dbl>  <chr> <dbl>  
1  07 01  62  07/01  69  
2  07 02  61  07/02  67  
3  07 03  60  07/03  66  
4  07 04  60  07/04  64  
5  07 05  60  07/05  65  
6  07 06  61  07/06  66  
7  07 07  61  07/07  67  
8  07 08  61  07/08  69  
9  07 09  61  07/09  70  
10  07 10  62  07/10  69  

Hier ist der Plot-Code:

plot(Tmp_min ~ as.Date(y$MonthDay_min, format='%m/%d'), data=y, type="l", 
col="turquoise", ylab="Temperature (F)", 
    main=paste("Minimum and Maximum Daily Temperatures"), xlab="Month", 
    ylim=c(0,100)) 

points(Tmp_max ~ as.Date(y$MonthDay_min, format='%m/%d'), data=y, type="l", 
    col="orange", ylim=c(0,100)) 

Hier ist das Liniendiagramm: Minimum and maximum temperatures

Hier ist das Punktdiagramm: enter image description here

+1

was die Min- und Max-Datum in Ihrem Datensatz? Ich denke, weil Sie kein Jahr haben, haben Sie vielleicht ein "Zeitreise" Problem ... – pyll

+0

Das Mindestdatum ist 07/01 und das Maximum ist 06/30 (beginnend am 01.07.16, endet am 30.06/17). Ich habe versucht, das so zu setzen, dass es bei 7/1 begann und bei 6/30 endete, aber ich konnte das nicht zur Arbeit bringen - nur Plots Jan - Dez – kslayerr

+0

Ich bin zu 99% sicher, dass dieses Problem auf kein Jahr zurückzuführen ist. – pyll

Antwort

1

Dieses Problem ist wahrscheinlich auf fehlende Jahr ... versuchen Sie ein Jahr hinzufügen.

MonthDay_min <- c('07/01', '07/02', '07/03', '07/04', '06/30') 
Tmp_min <- c(62, 70, 61, 58, 100) 
Tmp_max <- c(69, 78, 66, 64, 105) 

y <- data.frame(MonthDay_min, Tmp_min, Tmp_max) 

year <- c(2016, 2016, 2016, 2016, 2017) 

y$MonthDay_min <- paste(y$MonthDay_min, '/', year, sep = "") 

plot(Tmp_min ~ as.Date(y$MonthDay_min, format='%m/%d/%Y'), data=y, type="l", 
    col="turquoise", ylab="Temperature (F)", 
    main=paste("Minimum and Maximum Daily Temperatures"), xlab="Month", 
    ylim=c(0,100)) 

points(Tmp_max ~ as.Date(y$MonthDay_min, format='%m/%d/%Y'), data=y, type="l", 
     col="orange", ylim=c(0,100)) 
2

Wahrscheinlich dies geschieht, weil Sie das gleiche Start- und Enddatum haben (sie in den Jahren unterscheiden können, aber Sie haben Monat + Tag nur). Siehe Beispiel:

date_seq = seq.Date(from = as.Date("2017/1/1"), to = as.Date("2018/1/1"), by = "day") 
date_seq_month_day <- format(date_seq, format="%m-%d") 
daily_white_noise = rnorm(length(date_seq)) 
dataframe <-data.frame(days = date_seq_month_day, observations = daily_white_noise) 
plot(observations ~ as.Date(date_seq_month_day, format='%m-%d'), data=dataframe, type="l", col="turquoise", ylab="Temperature (F)", main=paste("Minimum and Maximum Daily Temperatures"), xlab="Month") 

Das Bild wird so sein: enter image description here

+0

Das war genau das Problem. Ich habe Jahre zu den Daten hinzugefügt und jetzt plottet es ohne die Linie. Vielen Dank für Ihre Antwort! – kslayerr

Verwandte Themen