में टिक अंकों से कुछ टेक्स्ट अंक निकालें मैं बैंकिंग के संबंध में गैर-डिफॉल्टर्स और डिफॉल्टर्स पर कुछ शोध कर रहा हूं। उस संदर्भ में मैं बार प्लॉट में कुछ स्कोर के सापेक्ष अपने वितरण की साजिश रच रहा हूं। जितना अधिक स्कोर, क्रेडिट रेटिंग बेहतर होगी।ggplot bar plot
चूंकि डिफ़ॉल्ट की संख्या गैर-डिफ़ॉल्ट की साजिश की तुलना में बहुत सीमित है, उसी बार प्लॉट पर डिफ़ॉल्ट और गैर-डिफ़ॉल्ट पर प्लॉटिंग बहुत कम नहीं है क्योंकि आप शायद ही कभी डिफ़ॉल्ट देख सकते हैं। मैं फिर डिफॉल्टर्स के स्कोर के आधार पर दूसरी बार साजिश बना देता हूं, लेकिन डिफॉल्टर्स और गैर-डिफॉल्टर्स के दोनों स्कोरों की पूर्ण बार साजिश के समान अंतराल पैमाने पर। मैं फिर पहली बार साजिश में ऊर्ध्वाधर रेखाएं जोड़ता हूं जो दर्शाता है कि उच्चतम और निम्नतम डिफॉल्टर स्कोर कहां स्थित है। यह देखने के लिए कि डिफॉल्टर्स का वितरण दोनों डिफॉल्टर्स और गैर-डिफॉल्टर्स के समग्र वितरण में फिट है।
एक्स-अक्ष आसानी से बहुत "भीड़" हो जाता है। मैं टिकों के लिए कुछ पाठ को हटाना चाहता हूं, लेकिन सभी टिक अंक नहीं।
नीचे कोड है जिसका उपयोग मैं प्रतिस्थापित (बीजित) यादृच्छिक डेटा के साथ बदल रहा हूं।
पहला बार प्लॉट वह है जो मैं टिक अंकों पर पाठ के संबंध में रखना चाहता हूं, लेकिन मुझे दूसरी बार साजिश में मेरे सभी टिक्स याद आ रहे हैं। दूसरी बार साजिश में "भीड़" -नेस दिखाया गया है!
library(ggplot2)
library(ggExtra)
#NDS represents non-defaults and DS defaults on the same scale
#although here being just some random normals for the sake of simplicity.
set.seed(10)
NDS<-rnorm(10000,sd=1)-2
DS<-rnorm(100,sd=2)-5
#Cutoffs are constructed such that intervals of size 0.3 contain all values
#of NDS & DS
minCutoff<--9.3
maxCutoff<-2.1
#Generate the actual interval "bins"
NDS_CUT<-cut(NDS,breaks=seq(minCutoff, maxCutoff, by = 0.3))
DS_CUT<-cut(DS,breaks=seq(minCutoff, maxCutoff, by = 0.3))
#Manually generate where to put the vertical lines for min(DS) and max(DS)
minDS_bar<-levels(cut(NDS,breaks=seq(minCutoff, maxCutoff, by = 0.3)))[1]
maxDS_bar<-levels(cut(NDS,breaks=seq(minCutoff, maxCutoff, by = 0.3)))[32]
#Generate data frame - seems stupid, but makes sense
#when the "real" data is used :-)
NDSdataframe<-cbind(as.data.frame(NDS_CUT),rep(factor("State-1"),length(NDS_CUT)))
colnames(NDSdataframe)<-c("Score","Action")
DSdataframe<-cbind(as.data.frame(DS_CUT),rep(factor("State-2"),length(DS_CUT)))
colnames(DSdataframe)<-c("Score","Action")
fulldataframe<-rbind(NDSdataframe,DSdataframe)
attach(fulldataframe)
#Plot the full distribution of NDS & DS with geom_vlines
#Get the tick texts I want to show
myLevels<-levels(cut(NDS,breaks=seq(roundDownNDS, roundUpNDS, by = 0.3)))
lengthMyLevels<-length(myLevels)
myBreaks<-seq(1,lengthMyLevels,3)
chosenbreaks<-myLevels[myBreaks[1]]
for(i in 2:length(myBreaks))
{
chosenbreaks<-rbind(chosenbreaks,myLevels[myBreaks[i]])
}
#Generate the plot of both NDS & DS
fullplot<-ggplot(fulldataframe, aes(Score, fill=factor(Action,levels=c("State- 2","State-1")))) + geom_bar(position="stack") + opts(axis.text.x = theme_text(angle = 45,size=8)) + opts(legend.position = "none") + xlab("Scoreinterval") + ylab("Antal pr. interval") + geom_vline(aes(xintercept = minDS_bar, colour="red")) + geom_vline(aes(xintercept = maxDS_bar, colour="red")) + scale_x_discrete("test",breaks=chosenbreaks)
#Generate second dataframe for the plot of DS only
DSdataframe2<-cbind(na.omit(as.data.frame(DS_CUT)),rep(factor("Fallit"),length (na.omit(as.data.frame(DS_CUT)))))
colnames(DSdataframe2)<-c("theScore","theAction")
#Calculate max value for the DS
myMax<-max(table(DSdataframe2))+1
attach(DSdataframe2)
#Generate plot for the DS only
subplot<-ggplot(fulldataframe, aes(theScore, fill=factor(theAction))) + geom_bar (position="stack") + opts(axis.text.x = theme_text(angle = 45)) + opts(legend.position = "none") + ylim(0, myMax) + xlab("Scoreinterval") + ylab("Antal pr. interval")
#Using the ggExtra package the to plots are aligned
align.plots(fullplot, subplot)
detach(DSdataframe2)
detach(fulldataframe)
किसी भी मदद की बहुत सराहना की जाती है!
धन्यवाद,
ईसाई
मीठा वैकल्पिक हल !! आपका बहुत बहुत धन्यवाद! –
'ggplot2 :: interleave' वर्तमान ggplot2 लाइब्रेरी (संस्करण 2.0.0) में नहीं मिला है। इस फ़ंक्शन का विकल्प क्या है? – user890739
@ user890739 इंटरलीव फ़ंक्शन, 'ggplot2 ::: interleave' तक पहुंचने के लिए आपको एक तिहाई कोलन की आवश्यकता होगी। हालांकि, अपने कार्यों पर ट्रिपल कॉलन का उपयोग करना याद रखें, क्योंकि ये फ़ंक्शंस पैकेज में आंतरिक बने रहने के लिए हैं; देखें: https://stat.ethz.ch/R-manual/R-devel/library/base/html/ns-dblcolon.html – aseagram