更改行标签和列标签热图plot_ly R

时间:2017-01-08 12:57:50

标签: r heatmap plotly

所以我使用plot_ly构建热图,并希望行和列标签是我的数据矩阵(a)中的行名和列名。我尝试过以下代码,但仍然无法更改标签:

vals <- unique(scales::rescale(c(a)))
o <- order(vals, decreasing = FALSE)
cols <- scales::col_numeric("Blues", domain = NULL)(vals)
colz <- setNames(data.frame(vals[o], cols[o]), NULL)
plot_ly(z = a, colorscale=colz,type = "heatmap") %>%
 layout(xaxis = list(colnames(a)), yaxis = list(rownames(a)))

布局部分似乎没有更新x和y轴?

我附上了我目前正在观看的视频图片。

graph of heatmap with wrong column and row labels 我想要的行名称是

"BILL_AMT1"                "BILL_AMT2"                "BILL_AMT5"               
"ID"                       "LIMIT_BAL"                "PAY_0"                   
"PAY_2"                    "PAY_3"                    "PAY_4"                   
"PAY_5"                    "PAY_6"                    "PAY_AMT2"                
"PAY_AMT4"                 "PAY_AMT6"                 "SEX"                     
"EDUCATION"                "MARRIAGE"                 "AGE"                     
"BILL_AMT3"                "BILL_AMT4"                "BILL_AMT6"               
"PAY_AMT1"                 "PAY_AMT3"                 "PAY_AMT5"                
"avg_bill_amt"             "avg_pay_amt"              "Bill_pay_diff1"          
"Bill_pay_diff2"           "Bill_pay_diff3"           "Bill_pay_diff4"          
"Bill_pay_diff5"           "Bill_pay_diff_prop_limit"

列名是;

"UnalteredTree" "CreatedFields" "CreatedSMOTE50.50" "CreatedSMOTE60.40" "CreatedSMOTE70.30"

dput(头(A)):

结构(c(0,0,0,18.1134012050694,3.29561403508772,0,16.8737510298348, 111.988517072994,238.103575444644,93.8902946420699,0,0,17.2492245114282, 126.35593664339,836.870398039609,476.448288146105,85.084473204874, 134.652264684817,50.7197832427989,70.9693694071751,593.541951819008, 406.736392972063,98.0032746143464,104.028924545005,37.1605151856135, 93.5877347492431,409.663438436698,137.4329664773,56.9190963166505, 61.7152642490207),. Dim = c(6L,5L),. Dimnames = list(c(&#34; BILL_AMT1&#34;, &#34; BILL_AMT2&#34;,&#34; BILL_AMT5&#34;,&#34; ID&#34;,&#34; LIMIT_BAL&#34;,&#34; PAY_0&#34;),c(&# 34; UnalteredTree&#34 ;, &#34; CreatedFields&#34;,&#34; CreatedSMOTE50.50&#34;,&#34; CreatedSMOTE60.40&#34;,&#34; CreatedSMOTE70.30&#34; )))

1 个答案:

答案 0 :(得分:0)

只需提供ylibrary(plotly) set.seed(1) m <- matrix(rnorm(9), nrow = 3, ncol = 3) dimnames(m) <- list(rownames(m, FALSE, "r"), colnames(m, FALSE, "c")) plot_ly( x = colnames(m), y = rownames(m), z = m, type = "heatmap" ) 参数以及相应的参考:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000"
    android:gravity="center_horizontal">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            android:orientation="vertical">

            <RelativeLayout

                android:id="@+id/lin"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <Button
                    android:id="@+id/button"
                    android:layout_width="wrap_content"
                    android:layout_height="50dp"
                    android:layout_alignParentBottom="true"
                    android:layout_marginBottom="16dp"
                    android:background="#E74E4C"
                    android:gravity="bottom"
                    android:paddingLeft="24dp"
                    android:paddingRight="24dp" />
            </RelativeLayout>

            <ImageView
                android:id="@+id/imageone"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:layout_margin="16dp"
                android:background="#FFF"
                android:scaleType="centerCrop" />

            <ImageView
                android:id="@+id/imagetwo"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:layout_margin="16dp"
                android:background="#7823"
                android:scaleType="centerCrop" />


        </LinearLayout>

    </ScrollView>

</LinearLayout>