2 回答

TA貢獻(xiàn)1893條經(jīng)驗(yàn) 獲得超10個(gè)贊
看起來(lái)您發(fā)布的最后一個(gè)鏈接是在正確的軌道上,但您必須欺騙 python 來(lái)克服 R 所做的一些非標(biāo)準(zhǔn)評(píng)估。我可以通過(guò)在顏色名稱周圍設(shè)置兩組引號(hào)來(lái)使其工作:
(ggplot(faithful, aes(x='waiting'))
? ? + geom_line(aes(color="'red'"), stat='density', adjust=0.5)
? ? + geom_line(aes(color="'blue'"), stat='density')
? ? + geom_line(aes(color="'green'"), stat='density', adjust=2)
? ? + labs(title='Effect of ...',
? ? ? ? ? ?x='Time to next eruption (min)',
? ? ? ? ? ?y='Density')
? ? + scale_color_identity(guide='legend',name='My color legend')
)
您可以制作自己的標(biāo)簽,例如帖子:
(ggplot(faithful,aes(x='waiting'))
?+ geom_line(aes(color="'red'"),stat='density',adjust=.5)
?+ geom_line(aes(color="'blue'"),stat='density')
?+ geom_line(aes(color="'green'"), stat='density',adjust=2)
?+labs(title='Effect of ...',x='Time to next eruption (min)',
? ? ? ?y='Density')
?+ scale_color_identity(guide='legend',name='My colors',
? ? ? ? ? ? ? ? ? ? ? ? breaks=['red','blue','green'],
? ? ? ? ? ? ? ? ? ? ? ? labels=['Label 1','Label 2','Label 3']))
2

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊
將顏色放在引號(hào)中,例如'"red"'而不是'red'。
(ggplot(faithful, aes(x='waiting'))
+ geom_line(aes(color='"red"'), stat='density', adjust=0.5)
+ geom_line(aes(color='"blue"'), stat='density')
+ geom_line(aes(color='"green"'), stat='density', adjust=2)
+ labs(title='Effect of varying KDE smoothing parameter',
x='Time to next eruption (min)',
y='Density')
+ scale_color_identity(guide='legend')
)
添加回答
舉報(bào)