2015-06-04 51 views
0

我正在生成一個圖形和R,並希望X軸更加細化。上述使R中的X軸標籤更加細化

Tenure   Type Visits Members Percent 
1  0  Basic 122446 283975 0.4311858 
2  0  Premium 21190 44392 0.4773383 
3  1  Basic 92233 283975 0.3247927 
4  1  Premium 17909 44392 0.4034285 
5  2  Basic 42516 283975 0.1497174 
6  2  Premium 9613 44392 0.2165480 


plot(Visit_Curve$Tenure, Visit_Curve$Percent, type = "n", main = "Visit Curve") 
    lines(Visit_Curve$Tenure[Visit_Curve$Type == "Basic"], Visit_Curve$Percent[Visit_Curve$Type == "Basic"], col = "red") 
    lines(Visit_Curve$Tenure[Visit_Curve$Type == "Premium"], Visit_Curve$Percent[Visit_Curve$Type == "Premium"], col = "blue") 

的代碼產生一個圖表已x軸通過的50因子分解有一種方法能夠方便地定製在基礎R繪圖規模?也許每10或5點打勾?

感謝, 本

回答

2

只是要定製與axes = FALSE?axis

軸您可以大大清理你的代碼:

Visit_Curve <- read.table(header = TRUE, text = "Tenure   Type Visits Members Percent 
1  0  Basic 122446 283975 0.4311858 
2  0  Premium 21190 44392 0.4773383 
3  1  Basic 92233 283975 0.3247927 
4  1  Premium 17909 44392 0.4034285 
5  2  Basic 42516 283975 0.1497174 
6  2  Premium 9613 44392 0.2165480") 

with(Visit_Curve, { 
    plot(Tenure, Percent, type = 'n', main = 'Visit Curve', axes = FALSE) 
    axis(1, at = seq(0, 2, by = .15)) 
    axis(2, at = seq(.15, .45, by = .05), las = 1) 
    box('plot') 
    lines(Tenure[Type == 'Basic'], Percent[Type == 'Basic'], col = 'red') 
    lines(Tenure[Type == 'Premium'], Percent[Type == 'Premium'], col = 'blue') 
}) 

或單獨與xaxt = 'n'或抑制每個軸標籤yaxt = 'n'

with(Visit_Curve, { 
    plot(Tenure, Percent, type = 'n', main = 'Visit Curve', xaxt = 'n', las = 1) 
    axis(1, at = seq(0, 2, by = .15)) 
    lines(Tenure[Type == 'Basic'], Percent[Type == 'Basic'], col = 'red') 
    lines(Tenure[Type == 'Premium'], Percent[Type == 'Premium'], col = 'blue') 
}) 

enter image description here

或者使用ggplot2

library('ggplot2') 
ggplot(Visit_Curve, aes(Tenure, Percent, colour = Type)) + 
    geom_line() + 
    scale_x_continuous(breaks = seq(0, 2, .15)) + 
    labs(title = 'Visit Curve') 

enter image description here

+0

這是偉大的!謝謝! – mangodreamz