2017-05-19 38 views
-1

我最近對全球教育進行研究,下面的圖表是我研究的重要情節。如何調整以下ggplot2圖形?

motivation-performance of education

ggplot(sam_data,aes(JOY,PV)) + 
    geom_line(aes(colour = Individualism))+ 
    facet_grid(occupation~as.factor(Gender)) + 
    theme(legend.key.height = unit(2.0,"cm"),legend.text = element_text(size = 5,face = "plain")) + 
    scale_color_continuous("Individualism",labels=sam_data$country,breaks =sam_data$Individualism)+ 
    geom_smooth() 

而問題是很明顯的:

1)不同國家的相關線時被分割成性別和職業的所有組合成一個線,而不是不同的線路。

2)這個傳說是一團糟,因爲我想讓它清楚地表明與他們的個人主義水平相對應的國家。但是,我試圖調整圖例的許多參數,並沒有太多的工作。

3)另外,我不知道如何刪除breaks參數產生的白色間隙。任何想法都會很棒!

+1

請提供可重現的示例數據集。 – www

+0

我真的很抱歉@ ycw,因爲論文還沒有發表,數據不能按照我老闆的要求分享,我知道你很難提供幫助,所以任何想法或提示都會有幫助。謝謝你的理解。 – exteralvictor

+1

您的數據的一小部分將有所幫助。有時候,人們甚至會創建一些僞造的數據作爲示例來代表數據的特徵和性質。無需感到抱歉。我只是想增加獲得有用反饋的機會。 – www

回答

1

我已經通過調整ggplot函數中的aes參數解決了第二個問題。我的新代碼如下

ggplot(sam_data,aes(JOYSCIE,PV1SCIE,group = CNTRYID)) + 
geom_point(aes(color = Individualism.comp4))+ 
facet_grid(recode.OCOD3~as.factor(Gender0women1men)) + 
theme(legend.key.height = unit(3.0,"cm"),legend.text = element_text(size = 5,face = "plain")) + 
scale_color_gradientn("Individualism",labels=sam_data$CNTRYID,breaks =sam_data$Individualism.comp4,colors = rainbow(4))+ 
scale_x_continuous(limits = c(-2,2))