VK (이산) 및 relPrec (연속)의 두 가지 차원을 따라 플로팅하려는 데이터가 있습니다.
또한 두 가지 차원의 속성이 있습니다.
type <- c("relPrecAir", "relPrecInv", "relPrectotal")
p <- c(0.9, 0.95, 0.99)
type
모양과 p
색 으로 표현하고 싶습니다 . 다음 코드로 그렇게 할 수 있습니다.
precisionTable <- structure(list(relPrecTotal = c(0, 0, 0, 0.0070300473755567, 0.00842647198124317, 0.0112374693913644), relPrecAir = c(0, 0, 0, 0.00700370093237813, 0.00839489217055491, 0.011195354831821), relPrecInv = c(0, 0, 0, 0.0108917034179065, 0.0130551941937278, 0.0174102928813975), p = c(0.9, 0.95, 0.99, 0.9, 0.95, 0.99), VK = c(0, 0, 0, 1.15, 1.15, 1.15), case = c("demandStochastic", "demandStochastic", "demandStochastic", "demandStochastic", "demandStochastic", "demandStochastic")), .Names = c("relPrecTotal", "relPrecAir", "relPrecInv", "p", "VK", "case"), row.names = c(NA, -6L), class = "data.frame")
ggplot(precisionTable, aes(VK, relPrecTotal, color=as.factor(p))) + geom_line() + geom_point(shape=19) +
geom_line(aes(VK,relPrecAir, color=as.factor(p))) + geom_point(aes(VK,relPrecAir), shape=17) +
geom_line(aes(VK,relPrecInv, color=as.factor(p))) + geom_point(aes(VK,relPrecInv), shape=15) +
scale_color_discrete(name="p")
에 대한 하나의 범례가 표시됩니다 p
. 그러나 type
모양 값 으로 두 번째 범례를 그릴 수 없습니다 . 어떻게 추가 할 수 있습니까?
우리는 매개 변수에 대한 새 그룹을 추가하여 작업 할 수 있습니다 relPrecTotal
, relPrecAir
그리고 relPrecInv
, 다음 ggplot를 사용하여 플롯 진행합니다.
색상 범례에서 모양 재정의 편집
library(reshape2)
precisionTable2 <- melt(precisionTable, measure.vars = c("relPrecTotal", "relPrecAir", "relPrecInv"))
ggplot(precisionTable2, aes(VK, value)) +
geom_line(aes(color=as.factor(p), shape=as.factor(variable))) +
geom_point(aes(color=as.factor(p),shape=as.factor(variable))) +
scale_color_discrete(name='p') +
scale_shape_discrete(name='relPrec') +
guides(color=guide_legend(override.aes = list(shape=NA)))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다