全部,
我正在尋找一種在條形圖中相鄰顯示調查前和調查後問題的方法。 可能的響應(強烈不同意到強烈同意)應位於 x 軸,每個類別中響應的收件人數量應位於 y 軸。 但是,我想將每個響應值的值並排顯示,以顯示練習之前和之後的影響。 我可以使用圖形生成器將各組放在一起,但我無法將“強烈不同意”的值分組在一起,等等。任何幫助將不勝感激。
- 內森
下面的腳本生成一個表格,模擬 15 個問題的數據,其中 5 個主題各有 3 個問題,並有 20 名受訪者。 我不知道你的數據是如何組織的。 該表有 300 行 (20 x 5 x 3),標識符列(受訪者、問題 ID、性別、主題、前和後)。
為了使前/後欄可以並排,數據需要堆疊,換句話說,前/後是每個響應的標籤。
下面是一個顯示/示例顯示。 生成一些數據、堆疊數據、然後創建此圖的腳本如下圖所示。

Names Default to Here(1);
//Simulate a table of survey responses 20 respondents 15 questions: 3 questions per topic and 5 topics
//Gender is a respondent group, Topic is a question group
//responses are the Likert Scale
dt = New Table("Survey",
New Column("Respondent", Character, Nominal),
New Column ("Gender", Character, Nominal),
New Column("Question ID", Character, Ordinal),
New Column("Topic", Character, Nominal),
New Column("Pre", Ordinal),
New Column("Post", Ordinal)
);
dt << add rows(300);
dt:Pre << Value Labels(
{1 = "Strongly Disagree", 2 = "Disagree", 3 = "Neutral", 4 = "Agree",
5 = "Strongly Agree"}
);
dt:Post << Value Labels(
{1 = "Strongly Disagree", 2 = "Disagree", 3 = "Neutral", 4 = "Agree",
5 = "Strongly Agree"}
);
dt:Respondent << Set Each Value( Right("00" || Char(Sequence(1,20,1,15)),3) );
dt:Question ID << Set Each Value("Q" || Right("0"||char(Sequence(1,15,1,1)),2));
dt:Gender[1::150]="F";
dt:Gender[151::300]="M";
tlist = {"Food", "Technology", "Environment", "Energy", "Education" };
dt:Topic << Set Each Value( tlist[Sequence(1,5,1,3)]);
dt:Pre << Set Each Value(Random Integer(1,5));
//create some interest
dt:Post << Set Each Value(If(:Gender=="F" & :Pre==5, 5,
:Gender=="F", :Pre + 1,
:Gender=="M" & :Pre==1, 1,
:Gender=="M", :Pre -1
));
dt:Topic << Set Property("Value Ordering",
{"Food", "Technology", "Environment", "Energy", "Education"}
);
//Step2: Stack the table - the label for the data will be Pre and Post and as an Overlay variable for
//GraphBuilder the bars will be side by side
dt_stck= dt << Stack(
columns( :Pre, :Post ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ), Output Table Name("Stacked Pre Post Survey")
);
//Make sure Pre is ordered before Post
dt_stck:Label << Set Property("Value Ordering", {"Pre", "Post"});
gb = dt_stck << Graph Builder( // draw graph
Size( 881, 707 ),
Show Control Panel( 0 ),
Graph Spacing( 6 ),
Variables( X( :Data ), Wrap( :Question ID ), Overlay( :Label ) ),
Elements(
Bar( X, Legend( 13 ), Summary Statistic( "N" ), Label( "Label by Value" ) )
),
SendToReport(
Dispatch(
{},
"",
ScaleBox,
{Min( 0 ), Max( 12.5 ), Inc( 1 ), Minor Ticks( 0 ),
Label Row( Show Major Grid( 1 ) )}
),
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
13,
Properties( 0, {Fill Color( -10592673 )}, Item ID( "Pre", 1 ) ),
Properties(
1,
{Fill Color( 37 ), Fill Pattern( "left slant heavy b" )},
Item ID( "Post", 1 )
)
)}
)
)
);
如果有更多細節,這個問題會更容易回答,例如,組是什麼意思? 問題組或受訪者組。通常,當數據堆疊時,排列條形會更容易。
如果您可以顯示數據的佈局而不顯示特定值,那將會很有幫助。